Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

java - Followup questions: Using Maven to only sign and deploy jars to Maven Central. Build and compilation is done entirely with Ant

See followup question: Followup part 2 -- Using Maven to only sign and deploy jars to Maven Central. Build and compilation is done entirely with Ant

This is a follow up to this question: How to use Maven to only sign three jars and push them to Maven Central?


My goal here is to have Maven sign and push the already created jars to Maven Central. The three jars

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

are located in R:jeffyprogramminguildxbnjava-0.1.1download

These jars are created independently, by my Ant build process. Maven is not used for building or compiling my project in any way--I'm only using it to put the jars on Maven Central. (With some help in my previous question, it seems the signing portion of my POM is at least a lot closer to what it needs to be.)

When executing mvn deploy, I'm getting the error Return code is: 401, ReasonPhrase: Unauthorized. Maven is not asking me for my key-passphrase, which I expect it should, and I don't see where this information (the location of my saved key?) is configured. (Signing files is new to me, so please forgive any incorrect terminology).

(Also, the project's groupId is com.github.xbn, but there is no xbn directory in

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

I've opened a support ticket on sonatype regarding this, although I don't know if it's part of the problem or not.)

Diagnostic information is below. If anyone can provide guidance, I really need it. Thank you.


Here is my pom.xml, which is located in

R:jeffyprogrammingsandboxxbnjavapom.xml

(Notice the jars are in a the build directory, not the sandbox.)

    <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>[email protected]</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:[email protected]:aliteralmind/xbnjava.git</connection>
          <url>scm:git:[email protected]:aliteralmind/xbnjava.git</url>
          <developerConnection>scm:git:[email protected]: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>

My settings.xml, which is located in

C:applicationsprogrammingapache-maven-3.2.2confsettings.xml

(The M2_HOME environment variable is set to C:applicationsprogrammingapache-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>

Here is the output from calling mvn deploy

[R:jeffyprogrammingsandboxxbnjava]mvn deploy > temp.txt
TCC: C:applicationsprogrammingapache-maven-3.1.1inmvn.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:jeffyprogrammingsandboxxbnjavapom.xml to C:Usersjeffy.m2
epositorycomgithubxbnxbnjava.1.2-SNAPSHOTxbnjava-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

(the failure portion:)

[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 us

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your settings.xml file configuration is the problem cause your Id's in your server configurations do not correspond with the entries in distributionManagement:

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

You have to use the following server id's:

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

They have to correspond with the entries in distributionManagement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...