New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modifying project classpath from init script should either work or fail #8173
Comments
I agree that there should be a clearer error message. I need to dig a it to understand why you can access a I believe the right way to achieve what you want is:
That is you add the plugin to the init script |
Yes, the following indeed works as expected, thanks: import com.github.benmanes.gradle.versions.VersionsPlugin
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
}
}
rootProject {
apply plugin: VersionsPlugin
} I didn't think that adding to the initscript classpath and then applying to the project would work. |
I'm surprised this works. When you do When you do Why I'm skeptical that this is actually working for you is that the init scripts classpath is not a parent of the build scripts. I can't think of any way in which you the task types coming from this JAR loaded in the init script would be the same as any referenced statically from the build script. |
@Vampire from my testing the following fails: // my.init.gradle
import com.github.benmanes.gradle.versions.VersionsPlugin
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
}
}
rootProject {
apply plugin: VersionsPlugin
} // build.gradle
tasks.withType(DependencyUpdatesTask) {
checkForGradleUpdate = true
} fails with:
could you share a reproducer demonstrating "it even works to do tasks.withType in the real script that the init plugin applies this to, nice"? |
For reference, the reason it fails is described in #4078 |
Even when applying via its id, not its class object? But are you sure it is this way?
I wondered the same after I understood those quirks a bit better in that other ticket where it was about script plugins. But it indeed works, just try it, I just retried to make sure. In the init script initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
}
}
rootProject {
apply plugin: com.github.benmanes.gradle.versions.VersionsPlugin
} Then doing in the real build script just plugins {
id 'com.github.ben-manes.versions' version '0.20.0' apply false
}
tasks.withType(com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask) { println it } the task is printed. |
@eskatos the reproducer is in my last comment, didn't see yours before I sent it. |
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. |
This is still relevant in 6.8.2. Actually I made another experiment that surprisingly worked, so it seems you can add to the class path using the original post code, because this works: rootProject {
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
}
}
}
apply(plugin = "com.github.ben-manes.versions") while having the apply in the init script like in the original post still fails with the same error. |
I tried to use the following init script:
The effect it has is
Plugin with id 'com.github.ben-manes.versions' not found.
.I guess that at the time the closure is applied to the root project it is too late to add to its classpath.
It would be nice if this would either work (or maybe with some other method that can add dependencies to the classpath) or if it would at least error out.
Well, it errors out, but I mean with "you cannot do this here" or something more meaningful, I think you know what I'm talking about. :-)
The text was updated successfully, but these errors were encountered: