gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.95k stars 4.75k forks source link

Groovy and Kotlin DSL automatically import ...repositories.PasswordCredentials instead of ...credentials.PasswordCredentials #6394

Open eskatos opened 6 years ago

eskatos commented 6 years ago

@JLLeitschuh commented on Fri Aug 10 2018

I'm not sure that it's intentional, but org.gradle.api.artifacts.repositories.PasswordCredentials is automatically imported instead of org.gradle.api.credentials.PasswordCredentials.

I don't think either need to be automatically imported, but if one were to be automatically imported, it would make more sense to import org.gradle.api.credentials.PasswordCredentials as it's the base type.

------------------------------------------------------------
Gradle 4.9
------------------------------------------------------------

Build time:   2018-07-16 08:14:03 UTC
Revision:     efcf8c1cf533b03c70f394f270f46a174c738efc

Kotlin DSL:   0.18.4
Kotlin:       1.2.41
Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_92 (Oracle Corporation 25.92-b14)
OS:           Mac OS X 10.13.5 x86_64

@eskatos commented on Thu Aug 16 2018

The Kotlin DSL takes implicit imports from a Gradle core internal service. @JLLeitschuh could you please check it's the same in Groovy scripts and report in gradle/gradle?


@JLLeitschuh commented on Thu Aug 16 2018

@eskatos It is the same in the groovy scripts.

def function(PasswordCredentials credentials) {

}

If you jump to declaration in IntelliJ for this you go to the org.gradle.api.artifacts.repositories.PasswordCredentials.

@eskatos Do you just want to move this issue for me with ZenHub?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

ljacomet commented 3 years ago

Could you share a reproducer / detailed instructions on how this affects users?

eskatos commented 1 year ago

Confirmed it is still the case with Gradle 8.3 with both Groovy and Kotlin DSLs.

As for a reproducer, simply try to use PasswordCredentials where org.gradle.api.credentials.PasswordCredentials is expected:

repositories {
    maven {
        credentials(PasswordCredentials) { // HERE
        }
    }
}

Script compilation will fail. The IDE will show red squiggles and is of no help, it doesn't suggest importing the other type with the same name.

On the positive side, when you actually write PasswordCre.. the IDE suggests both imports.

The workaround is to import the right type.

eskatos commented 1 year ago

Thank you for providing a valid report.

The issue is in the backlog of the relevant team, but the existence of a workaround makes it non-critical, so it might take a while before a fix is made.