Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classification of artifacts in Gradle 5?

Tags:

android

gradle

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?

like image 474
Alix Avatar asked Feb 08 '19 10:02

Alix


People also ask

What are artifacts in Gradle?

Artifacts are temporary or final files or directories that are produced by the Android Gradle plugin during the build.

Which are the two types of plugins in Gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.

What is classpath in Gradle?

Gradle dependencies are grouped into sets called configurations. Different configurations are used for building classpath for the major two tasks — compile classpath is used for compilation and runtime classpath is used for running the application.

What is testImplementation in Gradle?

Configuration inheritance and composition For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.


1 Answers

Following will not show deprecation warning:

    archiveClassifier.set("sources")

    archiveClassifier.set("javadoc")
like image 139
Joel Handwell Avatar answered Sep 30 '22 23:09

Joel Handwell