如何使用Maven只签三个罐子并将它们推送到Maven Central?

时间:2014-07-16 02:51:59

标签: java maven ant

更新:请参阅followup question


我有一个Java库,其构建过程完全用Ant编写。项目的沙箱(源目录,我在其中编辑代码)是

R:\jeffy\programming\sandbox\xbnjava\

其构建(输出)目录是

R:\jeffy\programming\build\xbnjava-0.1.1\

这就是我的目标:

  1. ant cleanpublish:从头开始构建项目,包括创建这三个罐子

    • mylibrary-0.1.1.jar
    • mylibrary-0.1.1-sources.jar
    • mylibrary-0.1.1-javadoc.jar

    放入

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

    这部分已经完成并且效果很好。这三个罐子是Maven Central的as required(向上滚动一点就可以看到它)。

  2. 将版本检入GitHub并将构建目录上传到我的Web服务器。我也完成了这一步。

  3. mvn deploy需要做的就是签下三个罐子并将它们推送到Maven Central。这是我现存的祸根。


  4. 这是我到目前为止所采取的步骤:我有

    1. Set up my project at sonatype,
    2. Created my public key gpg4win(声纳类型为related documentation
    3. Downloadedinstalled Maven
    4. 设置我希望correct settings.xml的内容:

      <?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>MY_SONATYPE_USERNAME</username>
               <password>MY_SONATYPE_PASSWORD</password>
            </server>
            <server>
               <id>sonatype-nexus-staging</id>
               <username>MY_SONATYPE_USERNAME</username>
               <password>MY_SONATYPE_PASSWORD</password>
            </server>
         </servers>
         <pluginGroups></pluginGroups>
         <proxies></proxies>
         <mirrors></mirrors>
         <profiles></profiles>
      </settings>
      
    5. (此文件存储在R:\jeffy\programming\sandbox\settings.xml中,因为我的每个项目都使用该文件。)

      1. 根据the one in ez-vcardthe author's有帮助blog post中的引用)至少设置pom.xml的开头。我还使用Maven的introduction to the POM作为指南。
      2. 这些部分,在顶部,我相信我理解:

        <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>jar</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>
        
           <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>
           </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.apache.maven.plugins</groupId>
                         <artifactId>maven-gpg-plugin</artifactId>
                         <version>1.4</version>
                         <executions>
                            <execution>
                               <id>sign-artifacts</id>
                               <phase>package</phase>
                               <goals>
                                  <goal>sign</goal>
                               </goals>
                            </execution>
                         </executions>
                      </plugin>
                   </plugins>
                </build>
             </profile>
          </profiles>
        </project>
        

        我需要做什么来完成POM,其路径是

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

        所以它签署并推送这三个jar文件,如

        中所示
        R:\jeffy\programming\build\xbnjava-0.1.1\download\
        

        到Maven Central?

        我真的很感激有关从哪里开始的建议。我现在已经三天没有游泳,只有Maven文件,而且我迷失了,感到沮丧。这是我过去几年与Maven的第三次尝试,而且每次都非常糟糕。

        (我最初尝试fulfill Maven requirements with Ant tasks,但我决定完全将我的Ant版本和Maven签名-jars-and-push-to-Maven-Central部分分开。这是为了学习新东西,也因为看起来在Ant中实现Maven似乎不仅仅是纯Maven的标准。)

        感谢您帮助我。

1 个答案:

答案 0 :(得分:2)

如果要在Maven之外构建工件,则需要在.pom文件中引用它们

首先,将项目的packaging设置为pom,以便Maven不会尝试编译任何内容。

然后使用build-helper-maven-plugin将工件文件附加到项目中。这是一个例子:

    <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>build/xbnjava-0.1.1/download/mylibrary-0.1.1.jar</file>
                            <type>jar</type>
                        </artifact>
                        <artifact>
                            <file>build/xbnjava-0.1.1/download/mylibrary-0.1.1-javadoc.jar</file>
                            <type>jar</type>
                            <classifier>javadoc</classifier>
                        </artifact>
                        <artifact>
                            <file>build/xbnjava-0.1.1/download/mylibrary-0.1.1-sources.jar</file>
                            <type>jar</type>
                            <classifier>sources</classifier>
                        </artifact>
                    </artifacts>
                </configuration>
            </execution>
        </executions>
    </plugin>

最后,将distributionManagement部分添加到指定{。3}}的.pom文件中。

您可以在here参考我自己的Maven项目设置,该设置是为了在Maven central上传手动构建的.jar文件而创建的。