当前位置: 首页 > 面试题库 >

后续问题:使用Maven仅签名jar并将其部署到Maven Central。构建和编译完全由Ant完成

关宏毅
2023-03-14
问题内容

请参阅后续问题: 后续部分2 –使用Maven仅将jar签名并部署到Maven Central。构建和编译完全由Ant完成

我的目标是让Maven签名并将 已创建的 jar 推送到Maven
Central。该三个jar

  • xbnjava-0.1.2.jar
  • xbnjava-0.1.2-sources.jar
  • xbnjava-0.1.2-javadoc.jar

位于 R:\jeffy\programming\build\xbnjava-0.1.1\download

这些jar由我的Ant构建过程独立创建。Maven不会以任何方式用于构建或编译我的项目-我只是用它来将罐子放在Maven
Central上。(在我上一个问题的帮助下,看来我的POM的签名部分至少与它所需要的接近。)

执行时mvn deploy,我得到错误Return code is: 401, ReasonPhrase: Unauthorized。Maven并没有要求我提供密钥密码,我希望它应该如此,而且我看不到此信息(保存的密钥的位置?)的配置位置。(对我来说,签名文件是新手,所以请原谅任何不正确的术语)。

(此外,该项目groupId位于com.github.xbn,但该xbn目录中没有目录

https://oss.sonatype.org/content/repositories/snapshots/com/github/

我已经为此打开了声呐支持票,尽管我不知道这是否是问题的一部分。)

诊断信息如下。如果有人可以提供指导,我真的很需要。谢谢。

这是我的pom.xml,位于

R:\jeffy\programming\sandbox\xbnjava\pom.xml

(请注意,罐子位于build目录中,而不是沙箱中。)

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.github.xbn</groupId>
       <artifactId>xbnjava</artifactId>
       <packaging>pom</packaging>
       <version>0.1.2-SNAPSHOT</version>
       <name>XBN-Java</name>
       <url>https://github.com/aliteralmind/xbnjava</url>
       <inceptionYear>2014</inceptionYear>
       <organization>
          <name>Jeff Epstein</name>
       </organization>
       <description>XBN-Java is a collection of generically-useful backend (server side, non-GUI) programming utilities, featuring RegexReplacer and FilteredLineIterator. XBN-Java is the foundation of Codelet (http://codelet.aliteralmind.com).</description>

       <parent>
          <groupId>org.sonatype.oss</groupId>
          <artifactId>oss-parent</artifactId>
          <version>7</version>
       </parent>

       <licenses>
          <license>
             <name>Lesser General Public License (LGPL) version 3.0</name>
             <url>https://www.gnu.org/licenses/lgpl-3.0.txt</url>
          </license>
          <license>
             <name>Apache Software License (ASL) version 2.0</name>
             <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
          </license>
       </licenses>

       <developers>
          <developer>
             <name>Jeff Epstein</name>
             <email>aliteralmind-github@yahoo.com</email>
             <roles>
                <role>Lead Developer</role>
             </roles>
          </developer>
       </developers>

       <issueManagement>
          <system>GitHub Issue Tracker</system>
          <url>https://github.com/aliteralmind/xbnjava/issues</url>
       </issueManagement>

       <distributionManagement>
          <snapshotRepository>
             <id>ossrh</id>
             <url>https://oss.sonatype.org/content/repositories/snapshots</url>
          </snapshotRepository>
       </distributionManagement>

       <scm>
          <connection>scm:git:git@github.com:aliteralmind/xbnjava.git</connection>
          <url>scm:git:git@github.com:aliteralmind/xbnjava.git</url>
          <developerConnection>scm:git:git@github.com:aliteralmind/xbnjava.git</developerConnection>
       </scm>

       <properties>
          <java.version>1.7</java.version>
          <jarprefix>../build/${project.artifactId}-${project.version}/download/${project.artifactId}-${project.version}</jarprefix>
       </properties>

       <profiles>
          <!--
          This profile will sign the JAR file, sources file, and javadocs file using the GPG key on the local machine.
          See: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven
          -->
          <profile>
             <id>release-sign-artifacts</id>
             <activation>
                <property>
                   <name>release</name>
                   <value>true</value>
                </property>
             </activation>
             <build>
                <plugins>
                   <plugin>
                      <groupId>org.codehaus.mojo</groupId>
                      <artifactId>build-helper-maven-plugin</artifactId>
                      <version>1.8</version>
                      <executions>
                         <execution>
                            <id>attach-artifacts</id>
                            <phase>package</phase>
                            <goals>
                               <goal>attach-artifact</goal>
                            </goals>
                            <configuration>
                               <artifacts>
                                  <artifact>
                                     <file>${jarprefix}.jar</file>
                                     <type>jar</type>
                                  </artifact>
                                  <artifact>
                                     <file>${jarprefix}-javadoc.jar</file>
                                     <type>jar</type>
                                     <classifier>javadoc</classifier>
                                  </artifact>
                                  <artifact>
                                     <file>${jarprefix}-sources.jar</file>
                                     <type>jar</type>
                                     <classifier>sources</classifier>
                                  </artifact>
                               </artifacts>
                            </configuration>
                         </execution>
                      </executions>
                   </plugin>
                </plugins>
             </build>
          </profile>
       </profiles>
</project>

我的settings.xml,位于

C:\applications\programming\apache-maven-3.2.2\conf\settings.xml

M2_HOME环境变量设置为C:\applications\programming\apache-maven-3.2.2

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
   <servers>
      <server>
         <id>sonatype-nexus-snapshots</id>
         <username>aliteralmind</username>
         <password>MY_SONATYPE_DOT_COM_PASSWORD </password>
      </server>
      <server>
         <id>sonatype-nexus-staging</id>
         <username>aliteralmind</username>
         <password>MY_SONATYPE_DOT_COM_PASSWORD </password>
      </server>
   </servers>

   <pluginGroups></pluginGroups>
   <proxies></proxies>
   <mirrors></mirrors>
   <profiles></profiles>
</settings>

这是调用的输出 mvn deploy

[R:\jeffy\programming\sandbox\xbnjava]mvn deploy > temp.txt
TCC: C:\applications\programming\apache-maven-3.1.1\bin\mvn.bat [182]  Missing SETLOCAL

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\xbn\xbnjava\0.1.2-SNAPSHOT\xbnjava-0.1.2-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Downloading: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/maven-metadata.xml

Uploading: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.150828-1.pom
2/4 KB
4/4 KB

(故障部分:)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.407 s
[INFO] Finished at: 2014-07-16T11:08:29-04:00
[INFO] Final Memory: 7M/19M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.150828-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.150828-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [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/MojoExecutionException

再一次,这次使用 mvn deploy -e

[R:\jeffy\programming\sandbox\xbnjava]mvn deploy -e >temp.txt
TCC: C:\applications\programming\apache-maven-3.1.1\bin\mvn.bat [182]  Missing SETLOCAL

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building XBN-Java 0.1.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ xbnjava ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ xbnjava ---
[INFO] Installing R:\jeffy\programming\sandbox\xbnjava\pom.xml to C:\Users\jeffy\.m2\repository\com\github\xbn\xbnjava\0.1.2-SNAPSHOT\xbnjava-0.1.2-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ xbnjava ---
Downloading: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/maven-metadata.xml

Uploading: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom
2/4 KB
4/4 KB

(故障部分:)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.357 s
[INFO] Finished at: 2014-07-16T10:28:45-04:00
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project xbnjava: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
  at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
  at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
  at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
  at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
  at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
  at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:193)
  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
  ... 19 more
Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
  at org.apache.maven.plugin.deploy.AbstractDeployMojo.deploy(AbstractDeployMojo.java:167)
  at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:149)
  ... 21 more
Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:337)
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:268)
  at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:413)
  at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
  ... 23 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.github.xbn:xbnjava:pom:0.1.2-20140716.142845-1 from/to ossrh (https://oss.sonatype.org/content/repositories/snapshots): Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1016)
  at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$6.wrap(WagonRepositoryConnector.java:1004)
  at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:895)
  at org.eclipse.aether.connector.wagon.WagonRepositoryConnector.put(WagonRepositoryConnector.java:522)
  at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:331)
  ... 26 more
Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: https://oss.sonatype.org/content/repositories/snapshots/com/github/xbn/xbnjava/0.1.2-SNAPSHOT/xbnjava-0.1.2-20140716.142845-1.pom. Return code is: 401, ReasonPhrase: Unauthorized.
  at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:573)
  at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:493)
  at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:474)
  at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:454)
  at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$PutTask.run(WagonRepositoryConnector.java:871)
  ... 28 more
[ERROR]
[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/MojoExecutionException

问题答案:

您的settings.xml文件配置是问题所在,因为您的服务器配置中的ID与distributionManagement中的条目不对应:

<distributionManagement>
  <snapshotRepository>
    <id>ossrh</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  </snapshotRepository>
</distributionManagement>

您必须使用以下服务器ID:

<server>
  <id>ossrh</id>
  <username>username</username>
  <password>password</password>
</server>

它们必须与distributionManagement中的条目相对应。



 类似资料:
  • 问题内容: 这是以下 问题 的后续措施: 后续问题:使用Maven仅将jar签名并部署到Maven Central。构建和编译完全由Ant完成 多亏了对先前问题的回答,以及声纳支持人员的一些建议,我才有了我的第一个“永无止境”。这是当前的输出: 根据此日志,以下文件已上传到 https://oss.sonatype.org/content/repositories/snapshots/com/gi

  • 请参阅后续问题:后续第2部分——使用Maven仅对JAR进行签名并将其部署到Maven Central。构建和编译完全由Ant完成 这是对这个问题的跟进:如何使用Maven只签三个罐子并将其推向Maven Central? 我的目标是让马文签名并把已经制作好的罐子推到马文中心。三个罐子 位于 这些JAR是由我的Ant构建过程独立创建的。Maven不用于以任何方式构建或编译我的项目——我只是用它将J

  • 以下是后续问题:使用Maven只对JAR进行签名并将其部署到Maven Central。构建和编译完全由Ant完成 感谢前面问题的答案,以及sonatype支持人员的一些建议,我刚刚经历了第一次“非失败”。以下是的当前输出: 根据该日志,以下文件已上载到 https://oss.sonatype.org/content/repositories/snapshots/com/github/alite

  • 更新:见后续问题 我有一个Java库,它的构建过程完全是用蚂蚁编写的。项目的沙盒(我编辑代码的源代码目录)是 它的构建(输出)目录是 这就是我的目标: > 它们被放置在 这部分已经完成,效果很好。这三个罐子是Maven Central所需的(向上滚动一点即可查看)。 将版本签入GitHub并将构建目录上载到我的web服务器。我也完成了这一步。 :唯一需要做的就是签署三个JAR并将其推送到Maven

  • 经过上一步的漫长等待,不出意外的话都能出包了。 完整刷机包的位置是: ~/android/sudamod/out/target/product/z2_plus/sudamod-71.2-xxxxxxxxxxxx-UNOFFICIAL-z2_plus.zip 把这个包刷入手机就好用了。 在这个目录下,还会有一个同名的 md5sum 文件,推荐把它一起放入手机,这样 recovery 刷入时会自动检测

  • 我的团队正在使用功能分支来实现新功能,并不断将快照构建部署到远程存储库中供我们的用户使用。因此,“部署”实际上只意味着“分发到远程Maven存储库”。我们目前只为master分支运行持续集成构建,而不是功能分支,原因如下:我们使用Maven构建我们的项目并将JavaDoc和源代码与JAR一起分发。 我现在的计划是为每个功能分支构建添加一个分类器,并期望在创建和部署如下工件时使用该分类器: > 分支