You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, the script src/main/*/java-library.gradle(.kts) has a plugin ID of java-library (assuming it has no package declaration).
Likewise, src/main/*/my/java-library.gradle(.kts) has a plugin ID of my.java-library as long as it has a package declaration of my.
By the way, it's impossible to create a plugin named java-library because it conflicts with a core plugin with the same name. But here I want to describe another problem.
When I implement a plugin with a package statement on Kotlin, it works according to the documentation. I could not succeed in doing the same on Groovy. If I add a package statement in the plugin having a .gradle extension like below:
Execution failed for task ':buildSrc:extractPluginRequests'.
Script '/Users/enbirr/IdeaProjects/precompiled-plugins/buildSrc/src/main/groovy/com/example/my-plugin.gradle' should not contain a package statement.
Without specifying the package in the plugin, I cannot use the plugin ID containing the package as suggested in the documentation - com.example.my-plugin. I assume that in this case, com and example are treated as directories rather than packages. Thus, I can only use my-plugin as the plugin identifier in the build script.
Is there a misleading in the documentation, or do I need to do something differently?
Gradle version: 8.7
Mac OS
Context (optional)
I am implementing navigation to the plugin source from its ID in IntelliJ IDEA for statements like
// build.gradle
plugins {
id 'my-plugin'
}
I found this issue while learning the documentation to find possible approaches for plugin implementation. I am looking for conditions that would allow me to verify that a file found for navigation is a Gradle plugin and not something else.
By the way, it's impossible to create a plugin named java-library because it conflicts with a core plugin with the same name. But here I want to describe another problem.
Indeed, the example should use a different name.
Is there a misleading in the documentation, or do I need to do something differently?
…igation
Initially, I added creation of some data:
- an additional build script, required for successful project building
- usage of a task from the plugin, to make sure that the plugin was implemented correctly.
Such data is useful for manual testing, but could be not used in these tests because they do not trigger Gradle sync. Navigation logic could work without this data, so I removed it to make tests shorter and increase readability.
Here are some hints for implementing Precompiled script plugins to avoid errors while building a Gradle project:
1) The plugin file should have `.gradle` or `.gradle.kts` extension
2) The file path should contain `/src/main/kotlin` or `/src/main/groovy` (depending on the language of a plugin)
3) If plugin ID is like `com.example.foo-plugin`, and the found file is `foo-plugin.gradle.kts`, then the file path should contain directories for packages: `/src/main/kotlin/com/example/foo-plugin.gradle.kts`
Also, there are more concise conditions below, but they require more tricky implementation, hence were not considered in the navigation logic:
4) Above mentioned `/src/**` folder should be placed either in
- buildSrc directory
- a module taht is a part of a composite build: such module should be included in root `settings.gradle` file with `importBuild` method
5) A build script in a module containing `/src` with Precompiled plugins should have included plugins applying support for the corresponding language
- `groovy-gradle-plugin` (for plugins on Groovy)
- 'org.gradle.kotlin.kotlin-dsl' (for plugins on Kotlin)
P. S. Regarding the 3rd condition. According to the documentation, package declaration is available for both Groovy and Kotlin plugins. I did not succeed in implementing such a plugin on Groovy, so created an issue in Gradle tracker:
gradle/gradle#28851
GitOrigin-RevId: 994b3d7e18821534e894e6bc61b56b63da2f9ef7
Issue type
Wrong or misleading information
Problem description
According to the documentation for Precompiled script plugins, there is an opportunity to add a package declaration for a plugin implemented either on Groovy or Kotlin:
By the way, it's impossible to create a plugin named
java-library
because it conflicts with a core plugin with the same name. But here I want to describe another problem.When I implement a plugin with a package statement on Kotlin, it works according to the documentation. I could not succeed in doing the same on Groovy. If I add a package statement in the plugin having a
.gradle
extension like below:I see an error from Gradle:
Without specifying the package in the plugin, I cannot use the plugin ID containing the package as suggested in the documentation -
com.example.my-plugin
. I assume that in this case,com
andexample
are treated as directories rather than packages. Thus, I can only usemy-plugin
as the plugin identifier in the build script.Is there a misleading in the documentation, or do I need to do something differently?
Gradle version: 8.7
Mac OS
Context (optional)
I am implementing navigation to the plugin source from its ID in IntelliJ IDEA for statements like
I found this issue while learning the documentation to find possible approaches for plugin implementation. I am looking for conditions that would allow me to verify that a file found for navigation is a Gradle plugin and not something else.
Page with the problem
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompile_script_plugin
The text was updated successfully, but these errors were encountered: