1

While building my project, there are two versions of org.bouncy-castle:bcprov required

  • org.bouncy-castle:bcprov-jdk12
  • org.bouncy-castle:bcprov-jdk16

So while listing down the dependency I am getting the jdkversion12

Is there any way to modify the POM file in such a way that jdkversion16 is listed first?

nwinkler
  • 52,665
  • 21
  • 154
  • 168

1 Answers1

3

You can exclude a dependency by specifying it like this - in your case, you would exclude the jdk12 one:

    <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                    <exclusion>
                            <groupId>org.bouncycastle</groupId>
                            <artifactId>bcprov-jdk12</artifactId>
                    </exclusion>
            </exclusions>
    </dependency>

This way, only the jdk16 one should be pulled in.

If you need to pull in one of the two based on where you're building and which version of the JDK is installed, you can use profiles to distinguish, e.g. like this:

<profile>
    <id>jdk12</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.2</jdk>
    </activation>
    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk16</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</profile>
<profile>
    <id>jdk16</id>
    <activation>
        <jdk>1.6</jdk>
    </activation>
    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</profile>

Example taken from: http://svn.apache.org/repos/asf/webservices/wss4j/trunk/pom.xml

nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • Thanks for the quick response . But I need both the jar files. is there a way to keep both the jars but, while listing it should list the jdk16 first. Also as you mentioned it is org.bouncycastle. – Paul Achinth Apr 02 '12 at 11:41
  • What do you mean when you say *listing*? Where should it be listed first? On the classpath? In the list of dependencies? – nwinkler Apr 02 '12 at 11:47
  • What's the relevance of that? What advantage is there if it is listed first? – nwinkler Apr 02 '12 at 11:52
  • In my native box which is jdk 1.2 compatible is using the org.bouncycastle jdk version12. But to provide some advanced feature in another module of the project ,jdk 1.6 is required (to provide json support). – Paul Achinth Apr 02 '12 at 11:58
  • I think you need to limit yourself to only one of them, since they define classes in the same package from what I understand, so whatever you have first in your classpath is going to be used. Please take a look at the profile example that I have added above. – nwinkler Apr 02 '12 at 12:08
  • Thing is I dont have direct access to the jar.I am getting this jar as the dependency from another jar – Paul Achinth Apr 02 '12 at 12:58
  • Then define the dependency and the exclusion in the profile. I'll update my example. – nwinkler Apr 02 '12 at 13:02
  • I can't limit to one of them since both are required. Any how thanks for the quick response – Paul Achinth Apr 02 '12 at 16:21