Skip to content
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

Plugin is incompatible with isolated projects feature #907

Closed
erdi opened this issue Feb 20, 2024 · 7 comments
Closed

Plugin is incompatible with isolated projects feature #907

erdi opened this issue Feb 20, 2024 · 7 comments

Comments

@erdi
Copy link

erdi commented Feb 20, 2024

Please check the User Guide before submitting "how do I do 'x'?" questions!

Shadow Version

8.1.1

Gradle Version

8.5

Expected Behavior

Plugin does not violate project isolation constraints, no errors are raised when a project to which the plugin is applied which also enables project isolation is being imported into IntelliJ.

Actual Behavior

An error is thrown when a project to which the plugin is applied which also enables project isolation is being imported into IntelliJ. The following stacktrace is present in the configuration cache report generated upon the error:

org.gradle.api.InvalidUserCodeException: Cannot access project ':' from project ':services'
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall$original(ShadowPlugin.groovy:24)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall(ShadowPlugin.groovy)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy:15)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy)
	at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:70)
	....

That's because the plugin calls getPlugins() on the rootProject instance from sub projects which is not compatible with isolated projects.

One fix for this problem would be to check if com.gradle.enterprise plugin is applied to the Settings object (because that's what you should be applying the plugin in newer versions to according to the docs) rather than the root project object but sadly you cannot get to an instance of Settings from an instance of Project. Another fix would be for the com.gradle.enterprise plugin to register itself as a plugin on Gradle instance (to which you can get from an instance of Project) together with an instance of GradleEnterpriseExtension but for that we would probably need core Gradle team to change the implementation as I don't believe this is happening now (hard to tell given com.gradle.enterprise is closed source).

As a workaround, I will reverse engineer com.github.jengelman.gradle.plugins.shadow.ShadowPlugin as I have a convention plugin applying it in my project and simply boil it down to:

project.with {
    plugins.apply(ShadowBasePlugin)
    plugins.withType(JavaPlugin) {
        plugins.apply(ShadowJavaPlugin)
    }
}

Nevertheless, it would be good if this plugin was compatible with project isolation out of the box.

@Goooler
Copy link
Member

Goooler commented Feb 21, 2024

Some limitations are tracked in gradle/gradle#22514.

@3flex
Copy link
Contributor

3flex commented Aug 16, 2024

Couple of things:

  1. Does this code even work properly anymore? The plugin coordinates have changed to "com.gradle.develocity". Assuming it doesn't, could this feature just be dropped?
  2. If there's a desire or need to keep it, could it be gated so it's only active if using Gradle 8.4 or below, or Gradle 8.5 if isolated projects is not being used? See "Build Features API" section in https://docs.gradle.org/8.5/release-notes.html#build-authoring-improvements

@liutikas
Copy link
Contributor

liutikas commented Oct 1, 2024

There are two violations of project isolation in this plugin:

Exception at `com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall$original(ShadowPlugin.groovy:25)`
org.gradle.api.InvalidUserCodeException: Project ':compose' cannot access 'Project.plugins' functionality on another project ':'
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall$original(ShadowPlugin.groovy:25)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall(ShadowPlugin.groovy)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy:14)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Exception at `com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall$original(ShadowPlugin.groovy:28)`
org.gradle.api.InvalidUserCodeException: Project ':compose' cannot access 'Project.plugins' functionality on another project ':'
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall$original(ShadowPlugin.groovy:28)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin$_apply_closure1.doCall(ShadowPlugin.groovy)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy:14)
	at com.github.jengelman.gradle.plugins.shadow.ShadowPlugin.apply(ShadowPlugin.groovy)
	at java.base/java.lang.Thread.run(Thread.java:1583)

liutikas added a commit to liutikas/shadow that referenced this issue Oct 1, 2024
Configuring develocity build scan additional detail publishing breaks
Gradle project isolation GradleUp#907

This change adds a new property com.gradleup.shadow.enableDevelocityIntegration
that defaults to true, however it allows folks to set it to false and
make shadow plugin usage project isolation safe.
@liutikas
Copy link
Contributor

liutikas commented Oct 1, 2024

Created #993 to help users disable this develocity integration.

@liutikas
Copy link
Contributor

liutikas commented Oct 2, 2024

Could we have a release to pick this up?

@Goooler
Copy link
Member

Goooler commented Oct 2, 2024

https://github.com/GradleUp/shadow/releases/tag/8.3.3

@3flex
Copy link
Contributor

3flex commented Oct 2, 2024

Can close this now then?

Thanks for turning this around so quickly both of you! I think I have one incompatible plugin to go before we can use this in detekt project.

@Goooler Goooler closed this as completed Oct 2, 2024
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Oct 2, 2024
Pulls in a fix GradleUp/shadow#907
to avoid project isolation violations

Bug: 358128051
Test: ./gradlew bOS --dry-run
Change-Id: Ib5f62c6e5616fddb0eef6849b3291fc38339c1b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants