一、问题描述
这里发布jar,用到了maven-gpg-plugin插件,采用命令行执行命令:
mvn gpg:sign-and-deploy-file -Durl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -DpomFile=xxx-common-1.0.2.pom -Dfile=xxx-common-1.0.2.jar
报兼容性错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-gpg-plugin:3.0.1:sign-and-deploy-file (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.462 s
[INFO] Finished at: 2022-03-13T07:47:25+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign-and-deploy-file (default-cli) on project standalone-pom: Execution default-cli of goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign-and-deploy-file failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign-and-deploy-file: java.lang.AbstractMethodError: org.apache.maven.plugins.gpg.SignAndDeployFileMojo$SimpleModelProblemCollector.add(Lorg/apache/maven/model/building/ModelProblemCollectorRequest;)V
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-gpg-plugin:3.0.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/E:/mavenRepository/org/apache/maven/plugins/maven-gpg-plugin/3.0.1/maven-gpg-plugin-3.0.1.jar
[ERROR] urls[1] = file:/E:/mavenRepository/org/sonatype/sisu/sisu-inject-bean/1.4.2/sisu-inject-bean-1.4.2.jar
[ERROR] urls[2] = file:/E:/mavenRepository/org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noaop.jar
[ERROR] urls[3] = file:/E:/mavenRepository/org/sonatype/aether/aether-util/1.7/aether-util-1.7.jar
[ERROR] urls[4] = file:/E:/mavenRepository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar
[ERROR] urls[5] = file:/E:/mavenRepository/org/codehaus/plexus/plexus-component-annotations/2.0.0/plexus-component-annotations-2.0.0.jar
[ERROR] urls[6] = file:/E:/mavenRepository/org/apache/maven/shared/maven-artifact-transfer/0.12.0/maven-artifact-transfer-0.12.0.jar
[ERROR] urls[7] = file:/E:/mavenRepository/org/apache/maven/shared/maven-common-artifact-filters/3.0.1/maven-common-artifact-filters-3.0.1.jar
[ERROR] urls[8] = file:/E:/mavenRepository/org/apache/maven/shared/maven-shared-utils/3.1.0/maven-shared-utils-3.1.0.jar
[ERROR] urls[9] = file:/E:/mavenRepository/commons-io/commons-io/2.5/commons-io-2.5.jar
[ERROR] urls[10] = file:/E:/mavenRepository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar
[ERROR] urls[11] = file:/E:/mavenRepository/org/codehaus/plexus/plexus-utils/3.3.0/plexus-utils-3.3.0.jar
[ERROR] urls[12] = file:/E:/mavenRepository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[13] = file:/E:/mavenRepository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
我在pom.xml文件里指定了版本号,没有生效
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
二、解决方法
pom.xml文件里的配置不生效,只能改maven默认的插件版本号,可通过如下格式指定版本号:
mvn groupID:artifactID:version:goal
修改成如下即可执行通过
mvn org.apache.maven.plugins:maven-gpg-plugin:1.5:sign-and-deploy-file -Durl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -DpomFile=xxx-common-1.0.2.pom -Dfile=xxx-common-1.0.2.jar