Step 1: Make sure if you have installed JDK, Maven, Github, etc.

Step 2: Create a Github account if you haven't already.

Step 3: Create a new Github repository.

Step 4: Add a new SSH key to your Github account

Step 5: Make sure your project is a Maven project or follow the migration process.

Step 6: Make sure coordinates are correct (rename packages if necessary).

Step 7: Create or edit project pom.xml with similarity content (replace on your information):

<?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>your-group-id</groupId>
    <artifactId>your-artifact-id</artifactId>
    <version>your-version</version>
    <packaging>nbm</packaging>
    <name>project-name</name>
    <url>common-project-url</url>
    <description>project-description</description>
    <developers>
        <developer>
            <id>your-username</id>
            <name>your-name</name>
            <email>your-email</email>
            <url>your-common-url</url>
        </developer>
    </developers>
    <scm>
        <connection>scm:git:https://github.com/project-url.git</connection>
        <developerConnection>scm:git:https://github.com/project-url.git</developerConnection>
        <url>https://github.com/project-url/tree/${project.scm.tag}</url>
        <tag>master</tag>
    </scm>
    <licenses>
        <license>
            <name>GNU GPL 2.0</name>
            <url>https://www.gnu.org/licenses/old-licenses/gpl-2.0.html</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
    <build>
        <plugins>
	        <plugin>
	            <groupId>org.sonatype.plugins</groupId>
            	<artifactId>nexus-staging-maven-plugin</artifactId>
            	<version>1.6.7</version>
            	<extensions>true</extensions>
            	<configuration>
                	<serverId>ossrh</serverId>
                	<nexusUrl>https://oss.sonatype.org/</nexusUrl>
                	<autoReleaseAfterClose>true</autoReleaseAfterClose>
            	</configuration>
        	</plugin>
            <plugin>
                <groupId>org.apache.netbeans.utilities</groupId>
                <artifactId>nbm-maven-plugin</artifactId>
                <version>4.3</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
	<dependencies>
		<!-- Add your project dependencies! -->
	</dependencies>
</project>

Step 8: Push the code to Github. 

Step 9: Sign up for a Sonatype Jira account.

Step 10: Create a Jira issue for new project hosting.
This triggers creation of your repositories. Normally, the process takes less than 2 business days. Why the wait?
Please do not deploy until after you have received an e-mail notice indicating that the ticket is Resolved. 
One of the most common problems related to new projects is premature deployment, which misroutes your artifacts to a catch-all repository.

Step 11: Install GNU PG or via package manager (Ubuntu example):

sudo apt-get install gpg

#.....

gpg --version
gpg (GnuPG) 2.2.4
libgcrypt 1.8.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

#......


Step 12:
 Generate the key pair (Enter a passphrase on request):

gpg --full-gen-key


Step 13:
Publish the GPG key pair and distribute your key to GPG servers:

gpg - -list-keys

gpg  - -keyserver [KEY_SERVER] - -send-key [KEY_ID]

Some of the key servers are: 


Step 14: Configuring Maven to know where to get the signing key. Modify or create <user-home>/.m2/settings.xml with content:

<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
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
        <localRepository/>
        <interactiveMode/>
        <offline/>
        <pluginGroups/>
        <servers>
            <server>
                <id>ossrh</id>
                <username>your-jira-id</username>
                <password>your-jira-pwd</password>
            </server>
        </servers>
        <mirrors/>
        <proxies/>
        <profiles>
            <profile>
                <id>ossrh</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <gpg.passphrase>passphrase-you-used-when-created-gpg-key</gpg.passphrase>
                </properties>
            </profile>
        </profiles>
        <activeProfiles/>
</settings>


Step 14:  Do the release!


A simple way (but sometimes doing something wrong):

mvn clean

mvn release:prepare

mvn release:perform


Manual method (full control over the process):

First, correct the version in the version tag of your: x.x.x - public releases or x.x.x-SNAPSHOT - developer releases. With SNAPSHOT prefix you make does unlimited pushes to nexus.

Then for public releases correct tag info in the tag from scm section.

Make commit, push changes with tag into your github repository.

Then execute in project folder:

mvn clean install

mvn deploy


Step 16: Verify the sonatype repository.

https://oss.sonatype.org/#nexus-search;quick~your-group-id

For Ant project plugins

You can also deploy your plugin to the Maven Central Repository without converting it to a Maven project.

First of all, please do the same steps as above until step 14 except step5.

Step 15: Add the Maven Ant Tasks to the lib directory.

e.g. yourproject/lib/maven-ant-tasks-2.1.3.jar

Step 16: Modify the build.xml

Please don't forget to add " xmlns:artifact="antlib:org.apache.maven.artifact.ant" to the project tag.

Please change the following:

  • your-group-id
  • your-artifact-id
  • your-version
  • your-code-name-base(changed dots to hyphens)

Note: You have to set the same version as build.xml to the manifest.mf and pom.xml.

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="your-code-name-base" default="netbeans" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
    <description>Builds, tests, and runs the project .</description>
    <import file="nbproject/build-impl.xml"/>

    <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" />

    <!-- define Maven coordinates -->
    <property name="build" value="build" />
    <property name="groupId" value="your-group-id" />
    <property name="artifactId" value="your-artifact-id" />
    <!-- don't forget change the versions of pom.xml and manifest.mf -->
    <property name="version" value="your-version" />
    <!-- defined maven snapshots and staging repository id and url -->
    <property name="ossrh-snapshots-repository-url"
              value="https://oss.sonatype.org/content/repositories/snapshots/" />
    <property name="ossrh-staging-repository-url"
              value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
    <!-- there server id in the Maven settings.xml -->
    <property name="ossrh-server-id" value="ossrh" />
    <property name="code-name-base" value="your-code-name-base(changed dots to hyphens)" />
    <property name="nbm-path" value="${build}/${artifactId}-${version}" />

    <!-- Need close and release on https://oss.sonatype.org after the nbm is uploaded -->
    <target name="deploy" depends="clean,nbm" description="deploy release version to Maven repository">
        <move file="${build}/${code-name-base}.nbm" toFile="${nbm-path}.nbm"/>
        <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${ossrh-staging-repository-url}" />
            <arg value="-DrepositoryId=${ossrh-server-id}" />
            <arg value="-DpomFile=pom.xml" />
            <arg value="-Dfile=${nbm-path}.nbm" />
            <arg value="-Pgpg" />
        </artifact:mvn>
    </target>
</project>

Step 17: Modify .gitignore

Add the following:

lib
pom.xml.asc

Step 18: Deploy to the Maven repository

cd /path/to/your/project
ant deploy
deploy:
     [move] Moving 1 file to /path/to/build
[artifact:mvn] [INFO] Scanning for projects...
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] Building 
[artifact:mvn] [INFO]    task-segment: [org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file] (aggregator-style)
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] [gpg:sign-and-deploy-file]
[artifact:mvn] gpg: *警告*: "--no-use-agent"は、使われなくなったオプションです - なんの効果もありません
[artifact:mvn] gpg: *警告*: "--no-use-agent"は、使われなくなったオプションです - なんの効果もありません
[artifact:mvn] Uploading: https://oss.sonatype.org/service/local/staging/deploy/maven2//your/group/id/your-artifactId/<version-number>/your-artifactId-<version-number>.nbm
[artifact:mvn] 640K uploaded
[artifact:mvn] [INFO] Retrieving previous metadata from ossrh
[artifact:mvn] [INFO] repository metadata for: 'artifact your-groupId:your-artifactId' could not be found on repository: ossrh, so will be created
[artifact:mvn] [INFO] Uploading repository metadata for: 'artifact your-groupId:your-artifactId'
[artifact:mvn] [INFO] Uploading project information for your-artifactId <version-number>
[artifact:mvn] [INFO] Uploading your-artifactId-<version-number>.pom.asc
[artifact:mvn] [INFO] Uploading your-artifactId-<version-number>.nbm.asc
[artifact:mvn] [INFO] Metadata[artifact your-groupId:your-artifactId].filename = maven-metadata.xml
[artifact:mvn] [INFO] Metadata[project your-groupId:your-artifactId].filename = your-artifactId-<version-number>.pom
[artifact:mvn] [INFO] Metadata[gpg signature your-groupId:your-artifactId:nbm:null:pom].filename = your-artifactId-<version-number>.pom.asc
[artifact:mvn] [INFO] Metadata[gpg signature your-groupId:your-artifactId:nbm:null].filename = your-artifactId-<version-number>.nbm.asc
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] BUILD SUCCESSFUL
[artifact:mvn] [INFO] ------------------------------------------------------------------------
[artifact:mvn] [INFO] Total time: 42 seconds
[artifact:mvn] [INFO] Finished at: Mon Jun 22 07:06:51 JST 2020
[artifact:mvn] [INFO] Final Memory: 27M/604M
[artifact:mvn] [INFO] ------------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 44 seconds

Step 19: Close and release on https://oss.sonatype.org

Also, see the following:

What's next?

Knowing your groupId and artifactId pair consider registering your plugin in Apache NetBeans Plugin Portal using this instruction.



  • No labels

5 Comments

  1. Can some kind volunteer please move the Ant to Maven migration procedure from legacy wiki.netbeans.org to this NetBeans Confluence space?

    http://wiki.netbeans.org/DevFaqMavenHowToMigrateFromANT

    1. The legacy wiki was already migrated to the new apache website. Should we fix the content there if we have to do it?

      https://netbeans.apache.org/wiki/DevFaqMavenHowToMigrateFromANT.asciidoc

      1. Oh yes, great. I have updated the link in this Confluence page to that new location. Thanks for the reminder.

  2. We may be carefull for the ant parts, the plugin used to the process is deprecated, I'm not sure how the replacement plugin https://maven.apache.org/resolver-ant-tasks/ is working

    1. I also noticed that. I used Maven Ant Task because it is used in the official document yet. I didn't try Maven Artifact Resolver Ant Tasks... It would be nice if someone tries it.