Skip to content

Commit a01f401

Browse files
committed
Honor system property to suppress Gradle API
This applies a workaround to gradle/plugin-portal-requests#260 when the Shadow plugin is applied where the local Gradle API is added to the `compileOnly` configuration even if the `org.gradle.unsafe.suppress-gradle-api` system property is used. Which, we do. This workaround is written in a way that even after this is fixed by the Plugin Publish plugin, it won't break anything. It just helps remove some clutter from the buildscript.
1 parent 167c12d commit a01f401

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtensionImpl.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.gradle.api.flow.FlowScope
1616
import org.gradle.api.model.ObjectFactory
1717
import org.gradle.api.plugins.BasePluginExtension
1818
import org.gradle.api.plugins.ExtensionAware
19+
import org.gradle.api.plugins.JavaPlugin
1920
import org.gradle.api.provider.Property
2021
import org.gradle.api.provider.Provider
2122
import org.gradle.api.provider.ProviderFactory
@@ -142,6 +143,15 @@ import static net.minecraftforge.gradleutils.GradleUtilsPlugin.LOGGER
142143
}
143144

144145
private void finish(Project project) {
146+
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
147+
// Publish Plugin: https://github.com/gradle/plugin-portal-requests/issues/260
148+
// Shadow: https://github.com/GradleUp/shadow/pull/1422
149+
if (this.providers.systemProperty('org.gradle.unsafe.suppress-gradle-api').map(Boolean.&parseBoolean).getOrElse(false)) {
150+
project.configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME) { compileOnly ->
151+
compileOnly.dependencies.remove(project.dependencies.gradleApi())
152+
}
153+
}
154+
145155
if (this.problems.test('net.minecraftforge.gradleutils.publishing.use-base-archives-name')) {
146156
project.extensions.getByType(PublishingExtension).publications.withType(MavenPublication).configureEach {
147157
it.artifactId = project.extensions.getByType(BasePluginExtension).archivesName

0 commit comments

Comments
 (0)