1

UPDATE: See followup question


I have a Java library whose build process is entirely written in Ant. The project's sandbox (the source directory, in which I edit the code) is

R:\jeffy\programming\sandbox\xbnjava\

Its build (output) directory is

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

This is what my goal is:

  1. ant cleanpublish: Builds the project from scratch, including creating these three jars

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

    which are placed into

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

    This part is done and works well. These three jars are as required by Maven Central (scroll up a tiny bit to see it).

  2. Check the version into GitHub and upload the build directory to my web server. I have also completed this step.

  3. mvn deploy: The only thing this needs to do is sign the three jars and push them to Maven Central. This is the current bane of my existence.


These are the steps I've taken so far: I have

  1. Set up my project at sonatype,
  2. Created my public key with gpg4win (related documentation on sonatype)
  3. Downloaded and installed Maven
  4. Set up what I hope is a 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>
    

(This file is stored in R:\jeffy\programming\sandbox\settings.xml, as it's used by every one of my projects.)

  1. Set up at least the beginning of my pom.xml, based on the one in ez-vcard (as referenced in the author's helpful blog post). I also used Maven's introduction to the POM as a guide.

These parts, at the top, I believe I understand:

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

The rest of it, I'm not so sure:

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

What do I need to do to complete the POM, whose path is

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

so it signs and pushes these three jar files, as located in

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

to Maven Central?

I would really appreciate some advice on where to go from here. I have been swimming in nothing but Maven documentation for three days now, and I'm lost and frustrated. This is my third attempt over the past few years with Maven, and each time it's gone very badly.

(I originally attempted to fulfill Maven requirements with Ant tasks, but I decided to instead completely separate my Ant build and the Maven sign-the-jars-and-push-to-Maven-Central portion. This is to learn something new, but also because it seems like implementing Maven within Ant is less of a standard than is just pure Maven.)

Thank you for helping me.

Community
  • 1
  • 1
aliteralmind
  • 19,847
  • 17
  • 77
  • 108

1 Answers1

2

If you are building your artifacts outside of Maven you need to reference them in your .pom file

At first, set the packaging of your project to pom so Maven will not attempt to compile anything.

Then use the build-helper-maven-plugin to attach your artifact files to the project. Here is an example:

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

Finally, add the distributionManagement section to your .pom file as specified here.

You can refer to my own Maven project setup at github which was created to upload manually built .jar files on Maven central.

Alexey Gavrilov
  • 10,593
  • 2
  • 38
  • 48
  • This looks promising. The only thing I don't understand is how it knows which directory the jars exist in. – aliteralmind Jul 16 '14 at 14:08
  • Is it just the path to your output directory? I have updated my answer. – Alexey Gavrilov Jul 16 '14 at 14:14
  • Okay, I see that. The POM is located in `C:\jeffy\programming\sandbox\xbnjava\ `, which is the project root. How does it know that `build/xbnjava-0.1.1/download/mylibrary-0.1.1-sources.jar` is located in `C:\jeffy\programming`? By pre-pending `../`? – aliteralmind Jul 16 '14 at 14:17
  • The paths in my answer might be wrong since depending on the location of the pom.xml file. I assumed that the pom.xml is in xbnjava directory, next to the build directory. You should put the paths relative to the pom.xml – Alexey Gavrilov Jul 16 '14 at 14:23
  • Thank you for your help @AlexeyGavrilov. Your help has gotten me farther, so thank you. I'm going to post another question, as I don't want to inundate you with follow-ups and diagnostic information (and ranting). It's just not happening. – aliteralmind Jul 16 '14 at 14:33
  • Followup questions: http://stackoverflow.com/questions/24784749/followup-questions-using-maven-to-only-sign-and-deploy-jars-to-maven-central-b – aliteralmind Jul 16 '14 at 15:38
  • Another followup: http://stackoverflow.com/questions/24793800/followup-2-using-maven-to-only-sign-and-deploy-jars-to-maven-central-build-a – aliteralmind Jul 17 '14 at 02:18