How to create a Maven asset?

Since making more use of Maven this year, I’ve come to really appreciate it. This makes we want to take some of my audio tools and make them available to others through the Maven repository.

Does anyone have a go-to tutorial or guide for the process that they’d like to recommend?

1 Like

It’s easier to make maven publications. Simplest way is to host your own maven repo on a Web Server.

In your gradle build file, ensure that this is the structure.

plugins {
    id 'java'
    id 'maven-publish'
}

group = 'com.yourdomain' // Reverse domain name
version = '1.0.0-SNAPSHOT'

This will set your publications there. Then you need to configure the output of the maven repo.

publishing {
    repositories {
        maven {
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
}

That is it. Now all you need to do is to clean build and publish.

$ ./gradlew clean build publish

Depending on the version you have there, repo will be generated in either $buildDir/repos/releases or $buildDir/repos/snapshots

Now all you need to do is to upload those to a web server. Assuming the following things:

  1. Your maven server is https://maven.yourdomain.com/
  2. It points to /var/www/ in your server
  3. The releases and snapshots directories created above are copied to the server directory

All it takes for someone to use your artifact is to define the server and add an implementation to it.

repositories {
    maven { url "https://maven.yourdomain.com/" }
}

dependencies {
    implementation "com.yourdomain:artifact-name:1.0.0-SNAPSHOT"
}

And they can use it.

The same process applies if you want to host in maven central. However, instead of your own server, you have to go via Sonatype Nexus, and ask them to host your files in there.

2 Likes

Road-block #1 – I’ve never used Gradle.
I guess I need to accept that resistance truly is futile.
The code I want to make available only has three classes and two interfaces.

Once I find time and brain-space learn to use yet another API/toolset, the explanation given looks clear and thorough. I have a genuine “thank you” and gratitude, SHC, for taking the time to write this up.

(A new laptop is due to arrive next week, 10th gen i7 with 12MB and SSD and touch screen! Should be a big step up from the current laptop that can take 15 minutes just to get into a semi-working state with 100% disk drive stats pegged. I’m planning to set the new laptop up as my main Java application work area. After that is running, I’ll try to set aside time to work on the growing backlog of audio-related projects. A Udemy course on Rest/SpringBoot is taking up the bulk of my free time at the moment.)

1 Like

The library books available on Gradle are 2016 or 17 at best and a bit out of date. But I did finally find the beginner docs at gradle.org. Completed this one today: Building Java Applications Sample It was a little tricky in that Gradle doesn’t work with Java 16 yet, so I had to install 15 as well. I can’t say I understand it all, yet. Have many more sections to read.

I also finally found the spot where Maven.org has directions for uploading content: Guide to uploading artifacts to the Central Repository So, am reading that as well. At least with AudioCue, I’ve already fulfilled one of the more onerous requirements which is to write a Javadoc. Am still reading through this section as well. Hoping this might actually happen. It’s been hard to see things through to completion.

1 Like