12

Problem: Publish javadoc and sources for a gradle project. The following code works well, even on Gradle 5.1.1:

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

However, in Gradle 5.1.1 the following statements are deprecated:

classifier = 'sources'

...

classifier = 'javadoc'

Looking at the javadoc for the evaluated method name reveals:

Deprecated. Use getArchiveClassifier()

Source: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/bundling/AbstractArchiveTask.html#setClassifier-java.lang.String-

This doesn't make sense to me.

What change is required for my code to continue to work and not be deprecated?

1
  • 4
    I asked the same question on the gradle forum a while ago: discuss.gradle.org/t/… You can really just use archiveClassifier = 'sources' instead. I guess it's some gradle magic involving special handling of properties.
    – eekboom
    Feb 8, 2019 at 13:19

1 Answer 1

19

Following will not show deprecation warning:

    archiveClassifier.set("sources")

    archiveClassifier.set("javadoc")
1
  • IntelliJ IDEA inspection produces warning: 'set' in 'org.gradle.api.provider.Property<T>' cannot be applied to '(java.lang.String)' ... although it still works okay Jul 23, 2019 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.