I'm using following setup:
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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With