Publish to local Nexus repository

·

1 min read

In the last post, I explained how to set up the Nexus repository on a local NAS server. So now it is time to publish some artifacts there.

Create a simple java project

In Intellij create a new Gradle project with Java libraries. Create directories: src/main/avro. In avro directory create a new Avro file. I can be a file created in this post. Edit build.gradle file:

plugins {
    id 'java'
    id 'com.github.davidmc24.gradle.plugin.avro' version '1.5.0'
    id 'maven-publish'
}

group 'com.lda'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url "http://packages.confluent.io/maven/"
        allowInsecureProtocol = true
    }
    maven { url "http://<nas-ip-address>:<nexus-port>/nexus/repository/maven-snapshots/"
        allowInsecureProtocol = true
    }
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    implementation 'io.confluent:kafka-avro-serializer:5.3.0'
    implementation 'org.apache.avro:avro:1.11.1'
}

test {
    useJUnitPlatform()
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allJava
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from(components.java)
            artifact sourcesJar
        }
    }
    repositories {
        maven {
            url 'http://<nas-ip-address>:<nexus-port>/nexus/repository/maven-snapshots/'
            allowInsecureProtocol = true
            credentials {
                username '<user_name>'
                password '<user_pass>'
            }
        }
    }
}

Of course, change project-specific settings and set the correct nexus settings.

Publis artifact

  1. Build gradle project

  2. Run Publis task - or execute in command line gradlew publish

  3. Go to Nexus GUI and browse maven-snapshot repository. A new artifact should be created.