gradlegroovypublishgroovydoc

publish groovy doc with gradle


I have a project with about 50% Java code and 50% Groovy that i try to publish to Sonatype ossrh. Publishing snapshots goes well but the docs jar is missing (both when publishing locally and publishing to Sonatype Nexus). I can create the combined groovy/java docs by defining:

groovydoc {
    use = true
    groovyClasspath = configurations.compile // http://issues.gradle.org/browse/GRADLE-1391
}

task groovydocJar(type: Jar, dependsOn: groovydoc ) {
    classifier 'javadoc' // must use javadoc classifier to be able to deploy to Sonatype
    from groovydoc.destinationDir
}

and running ./gradlew groovydocJar produces the intended -javadoc.jar without problems.

My issue is that this docs jar is not included the publish task.

I tried the following

publishing {
    publications {
        maven(MavenPublication) {
            from components.java

            artifacts {
                archives sourcesJar
                archives groovydocJar
            }

            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
            pom {
              // omitted for brevity
            }
        }
    }
}

... but e.g. `./gradlew publishToMavenLocal` publishes only the classes jar, the pom, a module and the sources jar. 
No sign of a javadoc jar. I thought this was the idea of the artifacts section but maybe something is missing. 
How can i tell the publishing task to include publishing of the groovydocs jar?

Gradle version is 6.8.3, jvm version is 1.8 and i depend on `compile 'org.codehaus.groovy:groovy-all:3.0.7'`

The complete build script is available here: 
https://github.com/perNyfelt/ProjectDeployer/blob/main/build.gradle

Solution

  • I figured it out:

    That artifacts.archives way was not working.

    The syntax for adding the groovy doc is like this:

    publishing {
        publications {
            maven(MavenPublication) {
                from components.java
    
                artifact(groovydocJar) {
                    classifier = 'javadoc'
                }
            // etc...
            }
        }
    }