Gradle Maven publish to nexus delombok source code
Asked Answered
B

1

9

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?

Biotechnology answered 19/3, 2019 at 23:31 Comment(0)
D
7

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.

Down answered 12/4, 2019 at 9:42 Comment(1)
Kotlin example: task<Jar>("sourcesJar") { archiveClassifier.set("sources") from(project.extensions.getByType<SourceSetContainer>()["main"].extensions["delombokTask"]) }Autostability

© 2022 - 2024 — McMap. All rights reserved.