简体   繁体   English

是否可以在POM中指定特定的JDK来运行给定的maven-plugin?

[英]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. 我被要求提供使用特定的JDK 1.8签名jar的协议,而该项目是1.7兼容的。 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 我有一个默认的JDK 1.8,詹金斯作业将使用它执行Maven作业

The application is 1.7 coded so in its pom.xml there is the following configuration: 应用程序是1.7编码的,因此在其pom.xml中具有以下配置:

 <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 .... 因为他们需要签名jar,并且建议他们使用1.8的jarsigner ,所以我想知道如何强制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? ... 使用JDK8可行吗? How? 怎么样?

many thanks 非常感谢

Francesco 弗朗切斯科

Just configure only JDK8 for this. 只需为此配置JDK8。

The maven-compiler-plugin will assure you to compile Java 1.7 compliant code. maven-compiler-plugin将确保您编译Java 1.7兼容代码。

On the other hand the maven-jarsigner-plugin will transparentely sign the jars using the JDK8. 另一方面, maven-jarsigner-plugin将使用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. 为了清楚jarsigner是一个JDK实用程序,不可能以较旧的版本(例如1.7)运行JDK 1.8的jarsigner

  1. Make sure that the desired JDK 8 is the only JDK in the compile classpath. 确保所需的JDK 8是编译类路径中唯一的JDK。
  2. In the POM, set the backward source and target version information (your example shows that you are already doing this). 在POM中,设置向后的源和目标版本信息(您的示例表明您已经在执行此操作)。
  3. Add the maven-jarsigner-plugin to the POM. 将maven-jarsigner-plugin添加到POM。
  4. Configure the desired JDK 8 jar signer. 配置所需的JDK 8 jar签名者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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