I'm making use of the Gradle maven
plugin to build an artefact that is to be used for another unrelated project. Along with the built .jar artefact, I would also like to generate and install the -javadoc.jar artefact along side it.
Using gradle clean build javadoc install
generates the JavaDoc in the local build file, and install the built artefact to the local repository, but it currently does not build and install -javadoc.jar along side it.
Is there a way to do this in Gradle using the maven
or javadoc
plugin? I don't mind writing a custom task to do it, but I rather use the "officially supported" way if one exists.
The build.gradle file:
project.group = "org.example.artefact"
project.version = "1.0-SNAPSHOT"
apply plugin: 'java'
apply plugin: 'maven'
dependencies {
// ...
}
uploadArchives {
repositories {
mavenDeployer {
// Custom repository location
repository(url: "file:///home/user/.m3/repository")
}
}
}
Javadocs are produced by the javadoc
task (I think you are mistakenly referring to it as a plugin). This task isn't actually executed by default when running build
or install
. Additionally you'll want to define a jar
task to bundle the javadocs and tell your build to publish that artifact by adding it to the artifacts {...}
block.
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
artifacts {
archives javadocJar
}
Running install
should then both create the javadoc jar and publish it to maven local. Additionally, running uploadArchives
would then publish that artifact to any configured repositories.
Edit: Updated to add definition of javadoc jar
task.
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