Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Maven publish to nexus delombok source code

I'm using following setup:

  • gradle 5.2.1
  • nexus publish
  • lombok 1.18.6
  • lombok gradle plugin io.freefair.lombok 3.1.4

I would like to upload sourceJar to nexus after delombok is done.

For maven publishing I use the following:

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

...

publications {
        maven(MavenPublication) {
            from components.java
            artifact sourcesJar
            artifact javadocJar
        }
    }

Sources uploaded to nexus are just one to one with my original source. How to change configuration so that uploaded sources are delombok sources?

like image 878
Jarek Jarmołowicz Avatar asked Mar 19 '19 23:03

Jarek Jarmołowicz


People also ask

How do I deploy Maven projects to Nexus?

By default, Maven handles the deployment mechanism via the maven-deploy-plugin – this mapped to the deployment phase of the default Maven lifecycle: The maven-deploy-plugin is a viable option to handle the task of deploying to artifacts of a project to Nexus, but it was not built to take full advantage of what Nexus has to offer.

What is the Gradle-Maven-publish-plugin?

Update dependency com.vanniktech:gradle-maven-publish-plugin to v0.21… Gradle plugin that creates a publish task to automatically upload all of your Java, Kotlin or Android libraries to any Maven instance. This plugin is based on Chris Banes initial implementation and has been enhanced to add Kotlin support and keep up with the latest changes.

How to set Gradle properties in multi module projects?

This Gradle plugin is using itself to publish any of the updates and sets the Gradle properties in this gradle.properties. In multi module projects you can set most properties in the root gradle.properties file and then only set the module specific ones in the submodules.

What is the Maven publish plugin?

The Maven Publish Plugin provides the ability to publish build artifacts to an Apache Maven repository. A module published to a Maven repository can be consumed by Maven, Gradle (see Declaring Dependencies) and other tools that understand the Maven repository format. You can learn about the fundamentals of publishing in Publishing Overview.


1 Answers

Here’s a self-contained example that produces the desired delomboked source JAR and publishes it to a Maven repository (using ./gradlew publishMavenPublicationToMyRepoRepository):

plugins {
  id 'java'
  id 'maven-publish'
  id 'io.freefair.lombok' version '3.1.4'
}

group = 'com.example'
version = '0.1'

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.6'
    annotationProcessor 'org.projectlombok:lombok:1.18.6'
}

task javadocJar(type: Jar) {
  from javadoc.destinationDir
  classifier = 'javadoc'
}

task sourcesJar(type: Jar) {
  ///////////////////////////////////////////////
  // This is the relevant change:
  from sourceSets.main.delombokTask
  ///////////////////////////////////////////////
  classifier = 'sources'
}

publishing {
  repositories {
    maven {
      name = 'myRepo'
      url = 'file:///tmp/myRepoDir'
    }
  }
  publications {
    maven(MavenPublication) {
      from components.java
      artifact sourcesJar
      artifact javadocJar
    }
  }
}

Please note that the example doesn’t use “nexus publish” but instead it simply publishes to a simple file system repository. As far as I understood your question, the actual uploading is not the problem but rather the creation of the delomboked source JAR.

like image 58
Chriki Avatar answered Oct 17 '22 07:10

Chriki