uleming
10/27/2024, 11:01 AMjava-library . Thus during local development user don't need credentials for publish task, and user should not publish those artifact (which is done in one of CI/CD tools).
But, and I assume that may be the IntelljIdea particularity, while project imported, the IDE executes and force to evaluate all parts of build script. This may be not true but my knowledge limited in here
The declaration is classic
publications {
repositories {
maven {
name ...
credentials {
// this part will fail if mavenUsername property is not available during IDE import
username = property["mavenUsername"] as String
password = property["mavenPassword"] as String
}
}
}
}
Since User don't actually need to publish while developing project in IDE, better to evaluate those credentials only when tasks publish executes.
So while project imported or "reload Gradle project" in IntelljIdea triggered the result is next
null cannot be cast to non-null type kotlin.String
I tried to introduce
class LazyCredentials: PasswordCredentials {
String getUsername(){
return providers.gradleProperty("mavenUsername") as String
}
String getPassword(){
return providers.gradleProperty("mavenPassword") as String
}
}
But as I expected it didn't work, the LazyCredentials not bound to task publish.
maven {
...
credentials(LazyCredentials::class){
}
}
I get
Unknown credentials type: 'Build_gradle$LazyCredentials' (supported types: org.gradle.api.artifacts.repositories.PasswordCredentials, org.gradle.api.credentials.AwsCredentials and org.gradle.api.credentials.HttpHeaderCredentials).
Looks like I miss something.
The current solution is to assign empty string (isn't beautefull) but works.
What else I tried
abstract class LazyCredentials : PasswordCredentials {
override fun getUsername(): String? {
return providers.gradleProperty("mvnUsername") as String?
}
override fun getPassword(): String? {
return providers.gradleProperty("mvnPassword") as String?
}
}
...
repositories {
maven {
name = "qtidev"
credentials(LazyCredentials::class.java) {
}
}
}
but kind of implementation is restricted
Unknown credentials type: 'Build_gradle$1$LazyCredentials' (supported types: org.gradle.api.artifacts.repositories.PasswordCredentials, org.gradle.api.credentials.AwsCredentials and org.gradle.api.credentials.HttpHeaderCredentials).
Current Gradle API doens't allow lazy credentialsMartin
10/27/2024, 11:15 AMnull during local devMartin
10/27/2024, 11:16 AMMartin
10/27/2024, 11:18 AMMartin
10/27/2024, 11:18 AMnull when you don't have the credentials around should unblock you (edit: or just empty string as you found out). Just rely on the fact that no publishing task will be calledPhilip W
10/27/2024, 11:47 AMMartin
10/27/2024, 12:33 PMcredentials(PasswordCredentials::class)How do you set user/password from there? Gradle properties?
Martin
10/27/2024, 12:34 PMCredentials will be provided from Gradle properties based on the repository name.Martin
10/27/2024, 12:35 PMmySecureRepositoryUsername=secret-user
mySecureRepositoryPassword=secret-password
Alright so it's ${repoName}Username /`${repoName}Password`Martin
10/27/2024, 12:37 PMcredentials {
username = findProperty("${repoName}Username")
password = findProperty("${repoName}Password")
}
Or is there some magic to PasswordCredentials::class ?Philip W
10/27/2024, 12:46 PMuleming
10/27/2024, 2:39 PMVampire
10/27/2024, 3:21 PMVampire
10/27/2024, 3:22 PMuleming
10/28/2024, 8:08 AMVampire
10/28/2024, 10:17 AMuleming
10/29/2024, 11:47 AM