Skip to content

Commit 6ab9ee7

Browse files
committed
Further cleanup and solidify buildscript
1 parent 47587c7 commit 6ab9ee7

File tree

3 files changed

+50
-37
lines changed

3 files changed

+50
-37
lines changed

build.gradle

+33-28
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
23

34
plugins {
4-
id 'dev.gradleplugins.gradle-plugin-development' apply false
5-
id 'java'
5+
id 'java-gradle-plugin'
66
id 'groovy'
77
id 'idea'
88
id 'eclipse'
99
id 'maven-publish'
1010
alias libs.plugins.licenser
1111
alias libs.plugins.gradleutils
12-
alias libs.plugins.plugin.publish apply false
12+
alias libs.plugins.plugin.publish
1313
alias libs.plugins.shadow
1414
}
1515

16-
// NOTE: Applying the Plugin Publish plugin causes local Gradle dependencies to be used
17-
// To develop using the target Gradle and Groovy versions, set this to 'false'
18-
final inCI = providers.environmentVariable('CI').<boolean>map({ 'true'.equalsIgnoreCase it }).getOrElse(false)
19-
20-
apply {
21-
if (!inCI) return
22-
plugin 'dev.gradleplugins.gradle-plugin-development'
23-
plugin libs.plugins.plugin.publish.get().pluginId
24-
}
25-
2616
final projectDisplayName = 'Forge Gradle Utilities'
2717
description = 'Small collection of utilities for standardizing MinecraftForge gradle scripts'
2818
group = 'net.minecraftforge'
@@ -31,22 +21,29 @@ version = gitversion.tagOffset
3121
println "Version: $version"
3222

3323
// Git Version requires Java 17
34-
java {
35-
toolchain.languageVersion = JavaLanguageVersion.of 17
36-
withSourcesJar()
37-
withJavadocJar()
38-
}
24+
java.toolchain.languageVersion = JavaLanguageVersion.of 17
3925

4026
configurations {
27+
// Applies the "Gradle Plugin API Version" attribute to configuration
28+
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
29+
def applyGradleVersionAttribute = { Configuration configuration ->
30+
configuration.attributes {
31+
attribute org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.get())
32+
}
33+
}
34+
35+
named JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute
36+
named JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute
37+
4138
named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) {
39+
// Fixes a conflict between Git Version's shadowed SLF4J from JGit and Gradle's own loggers
4240
exclude group: 'org.slf4j', module: 'slf4j-api'
4341
}
4442
}
4543

4644
dependencies {
4745
// Gradle API
48-
compileOnly gradleApi(libs.versions.gradle.get())
49-
compileOnly libs.groovy
46+
compileOnly libs.gradle
5047
compileOnly libs.nulls
5148

5249
// GitHub Actions Workflows
@@ -59,8 +56,18 @@ dependencies {
5956
implementation libs.jgit
6057
}
6158

59+
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
60+
// TODO [GradleUtils][GradleAPI] Remove this once they are fixed.
61+
// Publish Plugin: https://github.com/gradle/plugin-portal-requests/issues/260
62+
// Shadow: https://github.com/GradleUp/shadow/pull/1422
63+
afterEvaluate { project ->
64+
project.configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME) { compileOnly ->
65+
compileOnly.dependencies.remove project.dependencies.gradleApi()
66+
}
67+
}
68+
6269
license {
63-
header = file('LICENSE-header.txt')
70+
header = rootProject.file 'LICENSE-header.txt'
6471
newLine = false
6572
exclude '**/*.properties'
6673
}
@@ -79,13 +86,15 @@ tasks.withType(GroovyCompile).configureEach {
7986
groovyOptions.optimizationOptions.indy = true
8087
}
8188

82-
// TODO [GradleUtils][GU3] Remove, as normal JavaDocs are used instead, with Groovy classes being hidden impl
89+
// TODO [GradleUtils][GU3.0] Remove, as normal JavaDocs are used instead, with Groovy classes being hidden impl
8390
// javadocJar is created after evaluation, so we need to configure it here
8491
afterEvaluate {
8592
tasks.named('javadoc', Javadoc) { enabled = false }
8693
tasks.named('groovydoc', Groovydoc) { use = true }
8794

8895
tasks.named('javadocJar', Jar) {
96+
final groovydoc = tasks.named('groovydoc', Groovydoc).get()
97+
8998
dependsOn groovydoc
9099
from groovydoc.destinationDir
91100
}
@@ -96,9 +105,7 @@ changelog {
96105
publishAll = false
97106
}
98107

99-
// weird null-safe ?.tap is in case this extension doesn't exist.
100-
// see start of the buildscript. it's conditionally applied.
101-
extensions.findByType(GradlePluginDevelopmentExtension)?.tap {
108+
gradlePlugin {
102109
website.set gitversion.url
103110
vcsUrl.set gitversion.url + '.git'
104111

@@ -122,8 +129,6 @@ extensions.findByType(GradlePluginDevelopmentExtension)?.tap {
122129

123130
publishing {
124131
publications.register('pluginMaven', MavenPublication) {
125-
if (!inCI) from components.java
126-
127132
artifactId = project.name
128133

129134
changelog.publish it
@@ -138,7 +143,7 @@ publishing {
138143
license gradleutils.pom.licenses.LGPLv2_1
139144
}
140145

141-
// TODO [GradleUtils] Re-evaluate active developers in GU 3.0
146+
// TODO [GradleUtils][GU3.0] Re-evaluate active developers in GU 3.0
142147
developers {
143148
developer gradleutils.pom.developers.LexManos
144149
developer gradleutils.pom.developers.SizableShrimp

gradle.properties

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ org.gradle.parallel=true
33
org.gradle.configureondemand=true
44

55
# TODO [GradleUtils][Gradle9] Re-enable config cache in Gradle 9
6-
# Configuration Cache comes with too many bugs to be worth the trouble.
6+
# Configuration Cache causes issues with plugin publishing.
77
# Do continue to make our Gradle plugins (GU, FG7, etc.) support it though.
8-
org.gradle.configuration-cache=false
9-
org.gradle.configuration-cache.parallel=false
8+
#org.gradle.configuration-cache=true
9+
#org.gradle.configuration-cache.parallel=true
10+
11+
systemProp.org.gradle.unsafe.suppress-gradle-api=true

settings.gradle

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import dev.gradleplugins.GradleRuntimeCompatibility
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
5+
// GitHub Packages
6+
maven { url = 'https://maven.moddinglegacy.com/maven' }
7+
}
8+
}
29

310
plugins {
4-
id 'dev.gradleplugins.gradle-plugin-development' version '1.9.0'
11+
id 'me.jonathing.gradle.github-packages' version '2.0.0'
512
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.10.0'
613
}
714

@@ -10,6 +17,7 @@ rootProject.name = 'gradleutils'
1017
dependencyResolutionManagement {
1118
repositories {
1219
maven { url = 'https://maven.minecraftforge.net' }
20+
maven githubPackage.maven('remal-gradle-api/packages')
1321
mavenCentral()
1422
}
1523

@@ -20,10 +28,8 @@ dependencyResolutionManagement {
2028
plugin 'shadow', 'com.gradleup.shadow' version '9.0.0-beta13'
2129

2230
// Gradle API
23-
final gradle = '7.3'
24-
version 'gradle', gradle
25-
26-
library 'groovy', 'org.codehaus.groovy', 'groovy-all' version GradleRuntimeCompatibility.groovyVersionOf(gradle)
31+
version 'gradle', '7.3'
32+
library 'gradle', 'name.remal.gradle-api', 'gradle-api' versionRef 'gradle'
2733
library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2'
2834

2935
// GitHub Actions Workflows

0 commit comments

Comments
 (0)