How does Property<> class work in build configuration?

My task that builds sources jar to be published looked like this:

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

With gradle 5.1.1, IDEA complained about “classifier” being deprecated.
When I navigated to “classifier” I found:

/**
 * Sets the classifier.
 *
 * @deprecated Use {@link #getArchiveClassifier()}
 */
@Deprecated
public void setClassifier(@Nullable String classifier) {

Huh? The classifier setter is deprecated and the replacement is the archiveClassifier getter?!

I just tried it any, and found out it really works:

task sourcesJar(type: Jar) {
    archiveClassifier = 'sources'
    from sourceSets.main.allJava
}

Only now, IDEA is complaining "Access to ‘archiveClassifier’ exceeds its access rights. Cannot assign ‘String’ to ‘Property’.

So I guess that with some groovy/gradle magic the assignment

    archiveClassifier = 'sources'

gets transformed to

    getArchiveClassifier().set('sources')

Is that correct?
How does this work?
Is it documented somewhere?
Is the wrong warning in IDEA a bug in IDEA? How to I describe it best for IntelliJ’s issue tracker?

4 Likes

You need use archiveClassifier.set(“sources”)

When using archiveClassifier.set(“sources”), IntelliJ displays the warning:
‘set’ in ‘org.gradle.api.provider.Property’ cannot be applied to ‘(java.lang.String)’

3 Likes