Hello again. Is it possible, using Nokee's `gradle...
# plugin-development
j
Hello again. Is it possible, using Nokee's
gradle-plugin-development
plugin, to only use the Gradle API it offers? Here's a screenshot of my dependencies. IntelliJ is still including my Gradle wrapper's API files in the compile classpath. I should mention that I'm also applying
dev.gradleplugins.groovy-gradle-plugin
to the project's plugins.
v
Iirc that plugin adds
gradleApi()
to your dependencies for your, yes
j
Ok. Would I still be able to use
com.gradle.plugin-publish
if I don't use
java-gradle-plugin
?
v
I think so
👍 1
j
Unfortunately it looks like
com.gradle.plugin-publish
also adds the default
gradleApi()
dependency to the compile classpath. Removing that plugin (even on its own without
java-gradle-plugin
allows me to use the Nokee republish. On further inspection I believe this is because
com.gradle.plugin-publish
is applying the
java-gradle-plugin
. It's a little cursed, but right now I'm conditionally applying the plugins by doing this:
Copy code
plugins {
    id 'dev.gradleplugins.groovy-gradle-plugin' apply false
    id 'java'
    id 'groovy'
    alias libs.plugins.plugin.publish apply false
}

// NOTE: Applying the Plugin Publish plugin causes local Gradle dependencies to be used
final inCI = providers.environmentVariable('CI').<boolean>map({ 'true'.equalsIgnoreCase it }).getOrElse(false)
//final inCI = true

apply {
    if (!inCI) return
    plugin 'dev.gradleplugins.groovy-gradle-plugin'
    plugin libs.plugins.plugin.publish.get().pluginId
}

dependencies {
    // Gradle API
    if (!inCI) {
        compileOnly gradleApi(libs.versions.gradle.get())
        compileOnly libs.groovy
    }
}
And to configure the
gradlePlugins {}
extension, I am using
extensions.findByType(GradlePluginDevelopmentExtension)?.tap {}
so I can keep my IDE linting 😛
v
Oh, right, bad. Sorry. I forgot it does that and thought it just integrates with it.
extensions.findByType(GradlePluginDevelopmentExtension)?.tap {}
surely is able nicer. 😄 I recommend you switch to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio. And the above line could be
configure<GradlePluginDevelopmentExtension> { }
🙂
Looking at the sources, you can probably also set
org.gradle.unsafe.suppress-gradle-api
to prevent
gradleApi()
being added for you
j
I still prefer Groovy, I've been using it actively for way longer, but I'll give Kotlin another chance. It has been difficult to learn because of how much it strays away from Java's syntax and whatnot. I am very excited about DCL though 😁
I'll look at the suppress Gradle API property later as well, thanks
👌 1
v
From my PoV it was definitely worth to learn a bit Kotlin for that. Authoring builds is so much easier with proper IDE support. 🙂 But yeah, whatever works best for you, just a recommendation.
😁 1
👍 1
j
Unfortunately I haven't had any luck with the
org.gradle.unsafe.suppress-gradle-api
property. I tacked the debugger on
JavaGradlePluginPlugin#applyDependencies
and the property is making it skip adding the Gradle API to the api configuration as intended, but it's still being added in the final dependencies somehow. This even just with only the
java-gradle-plugin
. I scavenged the sources of Gradle 8.14 and found nothing else that might point to it being added. I'm adding it like this:
Copy code
systemProp.org.gradle.unsafe.suppress-gradle-api=true
org.gradle.unsafe.suppress-gradle-api=true
Just to make sure I'm not going crazy, I made a new gradle plugin project using
gradle init
and am getting the same problem there with a default setup.
Running ./gradlew plugindependencies with the system property shows that there is nothing in the api configuration, while without the system property it shows a dependency named "unspecified" (which I assume to be the Gradle API). But it looks like the IDE is completely unaware of what I'm trying to do.
Copy code
--- ./deps_no_prop.txt  2025-05-01 12:46:20.702822445 -0400
+++ ./deps_with_prop.txt        2025-05-01 12:46:28.501797627 -0400
@@ -10,7 +10,7 @@
 No dependencies
 
 api - API dependencies for the 'main' feature. (n)
-\--- unspecified (n)
+No dependencies
 
 apiElements - API elements for the 'main' feature. (n)
 No dependencies
@@ -140,6 +140,6 @@
 
 A web-based, searchable dependency report is available by adding the --scan option.
 
-BUILD SUCCESSFUL in 409ms
+BUILD SUCCESSFUL in 428ms
 1 actionable task: 1 executed
 Configuration cache entry stored.
Hey @Vampire 👋, sorry to bother. Was wondering if you'd be able to give any more insight on this
Ok, it seems that after a few hours of digging that ping might've been unnecessary, so I'm sorry 😓. It looks like I was confusing how IntelliJ was presenting its dependencies when it showed that
gradle-api-8.14.jar
was present as an external library. The
gradle init
project uses it as a dependency for the
test
and
functionalTest
suites. Setting the system property does make it disappear from the compile classpath and I get errors in the test class. So it looks like there's some other issue with the setup I've made for the project I was working on. But thank you for your help so far!
Update: I found the culprit https://github.com/GradleUp/shadow/blob/5e44c138592c37b5b01a3bbd23cc7ad468f5297e/s[…]/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.kt But also it looks like
com.gradle.plugin-publish
is doing the same thing.
PublishTaskShadowAction#manipulateDependencies
Copy code
private void manipulateDependencies(ConfigurationContainer configurations) {
    Dependency gradleApi = project.getDependencies().gradleApi();

    Configuration api = configurations.findByName("api");
    if (api != null) {
        api.getDependencies().remove(gradleApi);
    }

    Configuration compileOnly = configurations.findByName("compileOnly");
    if (compileOnly != null) {
        compileOnly.getDependencies().add(gradleApi);
    }
}
I'd appreciate it if someone at Gradle could address that internally, since it's a private plugin and all. If I could make a PR, I would! 😛
v
Who? Me?
I'm just a user like you and not in any way affiliated to Gradle
j
I meant "you" in general, whoops haha
I imagine that's what most of this slack is
v
Hopefully this will improve things anyway: https://github.com/gradle/build-tool-roadmap/issues/70
j
Yeah, I was looking at those
I'm just going to submit an issue for the plugin and a PR for shadow, then just do
compileOnly.dependencies.remove(dependencies.gradleApi()
to get by
👌 1