lkallas
lkallas

Reputation: 1406

Creating jars for Maven repository, how?

Googled this question but no straight answer was found sadly.

So, I have a Maven project. I want to upload my release to Maven Central Repository. This means I need to create 3-4 jar files:

  1. Compiled source jar
  2. Javadoc jar
  3. Source code jar
  4. Tests jar (optional)

How can I create all these jars? Add some configuration to POM?

BTW, I am using latest Netbeans IDE, but this shouldn't matter :)

Any help is appreciated!

EDIT

So this is my POM:

 <?xml version="1.0" encoding="UTF-8"?>
    <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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.company</groupId>
        <artifactId>sdk</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.antlr</groupId>
                    <artifactId>antlr4-maven-plugin</artifactId>
                    <version>4.5.3</version>
                    <executions>
                        <execution>
                            <id>antlr</id>
                            <goals>
                                <goal>antlr4</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>

Upvotes: 0

Views: 97

Answers (2)

Jeroen
Jeroen

Reputation: 3146

Maven can create these jars for your. Next to 1,2,3,4 you will also need to sign your release artifacts. To get the artifact into maven central I would advise you to read:

  1. The official Maven guide to get your artifact into maven central
  2. The guide from the Open Source Sonatype repository. It contains all the information you will need to know.

With regards to your pom.xml you can add a separate release profile, which builds all these artifacts for you.

Just add the following profile to your pom.xml

<profile>
  <id>release</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>${maven-source-plugin.version}</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>${maven-javadoc-plugin.version}</version>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <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>
</profile>

Now when you want to create the release you can just call:

mvn clean install -Prelease

and it will create all the required artifacts.

Upvotes: 2

HRgiger
HRgiger

Reputation: 2790

Take a look at this guide and this. You need to raise a ticket for a mirror repository of your choice, then you need to use additionally plugins for signing jar, generating documents, adding source and doing remote deployment for you.

Upvotes: 1

Related Questions