Third-party plugins cannot be applied by ID from external build scripts #1262
Comments
Big +1 to this. Another (related) place where this is an issue is init scripts. |
I think that rather than fixing this issue we should address remaining gaps and un-incubate new plugin DSL. As a part of that we should allow the plugins block in all script types including script plugins. |
@pioterj That would be another option. The |
Yes, that's what I meant by addressing the remaining gaps.
This is already available. |
Having this fixed would be highly appreciated! |
Probably the same root cause as #1894 (Unable to refer classes from extenal plugins in other *.gradle files). |
Is there any update for this? I'm trying to use the OWASP dependency check plugin in an external gradle script because we have hundreds of repositories and we don't want to include it in all the build.gradle files in each repo. This is the plugin - https://github.com/jeremylong/dependency-check-gradle I'm getting this when the following is added to an external gradle script. external-script.gradle: buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.owasp:dependency-check-gradle:2.1.1"
}
}
allprojects {
apply plugin: 'org.owasp.dependencycheck'
} Error:
|
@bzon your issue may be fixed by putting
Instead of
|
Any update on this issue. Fixing this issue will help maintain organization wide gradle files which can be directly imported (apply from) into new projects. |
Any update on the status of this? @wilkinsona have you seen this before? I tried to put |
Following a discussion on twitter with @melix on how to improve error message, in this case that the plugin with id cannot be found :
I propose the exception message suggest possible reasons for the error to happen, in this case one of the reason is this issue. Gradle could fail with a message like this (à la Mockito)
Also in this regard the website https://plugins.gradle.org/ could link to these issues where the plugin id cannot be used. Also it could be useful to also describe the way to apply a plugin with the class (with a warning of course). |
The same is also true for |
@emersonf Instead of :
use
You need to refer to the |
Looks like this bug is not going to be fixed for a while. Can we at least improve the error message? Something like:
|
Really looking forward to see this fixed. Took two hours of my time today... |
So I know this is fairly old, but I've ran into issues trying to use the plugin DSL in
Using
Should I make a separate issue for it on the kotlin dsl repo? |
reference > gradle/gradle#1262 (comment)
@haianhsing each buildscript uses its own classloader and cannot see plugins from peer scripts. See #1370. Additionally scripts applied from other scripts should apply plugins using the fully qualified classname though I don't remember the reason. You need to put those two plugin applications in the same gradle script file. It might even work if one is in the project build script and the other in an applied script I don't remember. |
@MarkRx Thanks for your answer! I know that The shared-build script is the common script and it include a lot of duplication of work. In addition, some other scripts apply it. So, put them in the same script is not the best way. Maybe there are some better solutions? |
@haianhsing It's possible to centralize resolution with pluginManagement, but it can be difficult to setup. For an example, take a look at this experiment. (Feel free to log an issue in that project if you have questions about what it's doing.) |
@nlwillia Finally, I find that running |
Using the implementation-class did not work work for me: script.gradle:
I still get the
Error. The implementation-class is defined here and I think I am using it correctly.
|
Ohh my. I had to drop the quotes. This was very subtle. The following script.gradle works fine:
Note that the |
- Use fully qualified class name when applying plugin to workaround gradle/gradle#1262
Signed-off-by: Lari Hotari <lari@hotari.net>
…by id Signed-off-by: Lari Hotari <lari@hotari.net>
@ahakanbaba not really, it can be followed by both. |
Signed-off-by: Lari Hotari <lari@hotari.net>
…by id Signed-off-by: Lari Hotari <lari@hotari.net>
Signed-off-by: Lari Hotari <lari@hotari.net>
…by id Signed-off-by: Lari Hotari <lari@hotari.net>
Signed-off-by: Lari Hotari <lari@hotari.net>
…by id Signed-off-by: Lari Hotari <lari@hotari.net>
Signed-off-by: Lari Hotari <lari@hotari.net>
…by id Signed-off-by: Lari Hotari <lari@hotari.net>
Note that it is now recommended to use the Example: https://docs.gradle.org/6.7-rc-2/samples/sample_convention_plugins.html |
But that doesn't make this issue less a bug, does it? |
Original issue: https://issues.gradle.org/browse/GRADLE-2136
Expected Behavior
An external plugin can be applied in a script plugin by ID. The plugin can be added to the build script's classpath and applied with the plugins DSL or the
buildscript
block.Current Behavior
An external plugin can only be applied in a script plugin by type. If applied in a script plugin an exception is thrown saying that the plugin cannot be found.
Context
This is an unnecessary limitation of Gradle's plugin system. Users run into the issue all the time. The limitation is not documented.
Steps to Reproduce (for bugs)
build.gradle:
script.gradle:
Another manifestation:
The text was updated successfully, but these errors were encountered: