简体   繁体   中英

Is it possible to specify in a POM a specific JDK to run a given maven-plugin?

I have been asked to provide for signing a jar using specific JDK 1.8 whereas project is being 1.7 compliant. How can I achieve this, assuming it is feasable? I have a default JDK 1.8 with which a jenkins job would execute a maven job

The application is 1.7 coded so in its pom.xml there is the following configuration:

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>           
        <artifactId>maven-compiler-plugin</artifactId>
        <version>.....</version>
        <configuration>
             .....
            <source>1.7</source>
            <target>1.7</target>
            .....
        </configuration>
  </plugin>

As they need to sign the jar, and they have been recommended to use jarsigner of 1.8 , I wonder how can I force maven-jarsigner-plugin ....

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jarsigner-plugin</artifactId>
   <version>...</version>
   <executions>
      <execution>
         <id>sign</id>
         <goals>
            <goal>sign</goal>
         </goals>
      </execution>
   </executions>
   <configuration>
      <keystore>${keystore.file}</keystore>
      <alias>${keystore.alias}</alias>
      <storepass>${keystore.password}</storepass>
      <storetype>${keystore.type}</storetype>
      <sigfile>XXX</sigfile>
   </configuration>
</plugin>

... to use JDK8 Is that feasable? How?

many thanks

Francesco

Just configure only JDK8 for this.

The maven-compiler-plugin will assure you to compile Java 1.7 compliant code.

On the other hand the maven-jarsigner-plugin will transparentely sign the jars using the JDK8.

Just to be clear jarsigner is a JDK utility, it's impossible to run jarsigner of JDK 1.8 in a older (say 1.7) version way.

  1. Make sure that the desired JDK 8 is the only JDK in the compile classpath.
  2. In the POM, set the backward source and target version information (your example shows that you are already doing this).
  3. Add the maven-jarsigner-plugin to the POM.
  4. Configure the desired JDK 8 jar signer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM