Skip to content

Commit 64eb819

Browse files
committed
3.0 - Full rewrite, Gradle 9, Java-centric API (#23)
1 parent 964d90e commit 64eb819

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2576
-1738
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permissions:
99

1010
jobs:
1111
build:
12-
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@main
12+
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@v0
1313
with:
1414
java: 17
1515
gradle_tasks: "publish publishPlugins"

build.gradle

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
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.groovy-gradle-plugin'
5+
id 'java-gradle-plugin'
6+
id 'groovy'
57
id 'idea'
68
id 'eclipse'
79
id 'maven-publish'
810
alias libs.plugins.licenser
911
alias libs.plugins.gradleutils
12+
alias libs.plugins.javadoc.links
1013
alias libs.plugins.plugin.publish
1114
alias libs.plugins.shadow
1215
}
1316

1417
final projectDisplayName = 'Forge Gradle Utilities'
18+
final projectArtifactId = base.archivesName = 'gradleutils'
1519
description = 'Small collection of utilities for standardizing MinecraftForge gradle scripts'
1620
group = 'net.minecraftforge'
1721
version = gitversion.tagOffset
1822

1923
println "Version: $version"
2024

21-
// Git Version requires Java 17
22-
java.toolchain.languageVersion = JavaLanguageVersion.of 17
25+
java {
26+
toolchain.languageVersion = JavaLanguageVersion.of(17)
27+
withSourcesJar()
28+
withJavadocJar()
29+
}
2330

2431
configurations {
2532
named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) {
2633
// Fixes a conflict between Git Version's shadowed SLF4J from JGit and Gradle's own loggers
2734
exclude group: 'org.slf4j', module: 'slf4j-api'
2835
}
29-
}
3036

31-
repositories {
32-
maven { url = 'https://maven.minecraftforge.net' }
33-
mavenCentral()
37+
// Applies the "Gradle Plugin API Version" attribute to configuration
38+
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
39+
def applyGradleVersionAttribute = { Configuration configuration ->
40+
configuration.attributes {
41+
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.get()))
42+
}
43+
}
44+
45+
// TODO [GradleUtils] Re-enable this after first publish of GradleUtils 3.0.0
46+
// named('apiElements', applyGradleVersionAttribute)
47+
// named('runtimeElements', applyGradleVersionAttribute)
48+
// named('shadowRuntimeElements', applyGradleVersionAttribute)
3449
}
3550

3651
dependencies {
37-
// Static Analysis
52+
// Gradle API
53+
compileOnly libs.gradle
3854
compileOnly libs.nulls
3955

56+
// JavaDoc Links Plugin
57+
compileOnly libs.gradle.javadoc.links
58+
4059
// GitHub Actions Workflows
4160
implementation libs.yaml
4261

43-
// Git Version
44-
implementation libs.gitver
45-
46-
// Backwards compatibility
47-
implementation libs.jgit
62+
// Tools
63+
implementation libs.bundles.utils
4864
}
4965

5066
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
@@ -58,7 +74,7 @@ afterEvaluate { project ->
5874
}
5975

6076
license {
61-
header = rootProject.file 'LICENSE-header.txt'
77+
header = rootProject.file('LICENSE-header.txt')
6278
newLine = false
6379
exclude '**/*.properties'
6480
}
@@ -68,7 +84,7 @@ tasks.named('jar', Jar) {
6884
}
6985

7086
tasks.named('shadowJar', ShadowJar) {
71-
enableRelocation = true
87+
enableAutoRelocation = true
7288
archiveClassifier = null
7389
relocationPrefix = 'net.minecraftforge.gradleutils.shadow'
7490
}
@@ -77,64 +93,58 @@ tasks.withType(GroovyCompile).configureEach {
7793
groovyOptions.optimizationOptions.indy = true
7894
}
7995

96+
tasks.withType(Javadoc).configureEach {
97+
javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(24) }
98+
99+
options { StandardJavadocDocletOptions options ->
100+
options.windowTitle = projectDisplayName + project.version
101+
options.tags 'apiNote:a:API Note:', 'implNote:a:Implementation Note:', 'implSpec:a:Implementation Requirements:'
102+
}
103+
}
104+
80105
changelog {
81106
fromBase()
82107
publishAll = false
83108
}
84109

85110
gradlePlugin {
86-
website.set gitversion.url
87-
vcsUrl.set gitversion.url + '.git'
88-
89-
compatibility {
90-
minimumGradleVersion = libs.versions.gradle.get()
91-
}
92-
93-
groovy {
94-
withSourcesJar()
95-
withGroovydocJar()
111+
website = gitversion.url
112+
vcsUrl = gitversion.url + '.git'
113+
114+
plugins.register('gradleutils') {
115+
id = 'net.minecraftforge.gradleutils'
116+
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
117+
displayName = projectDisplayName
118+
description = project.description
119+
tags.set(['minecraftforge'])
96120
}
121+
}
97122

98-
plugins {
99-
register('gradleutils') {
100-
id = 'net.minecraftforge.gradleutils'
101-
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
102-
displayName = projectDisplayName
103-
description = project.description
104-
tags = ['minecraftforge']
105-
}
106-
register('changelog') {
107-
id = 'net.minecraftforge.changelog'
108-
implementationClass = 'net.minecraftforge.gradleutils.changelog.ChangelogPlugin'
109-
displayName = 'Git Changelog'
110-
description = 'Creates a changelog text file based on git history using Git Version'
111-
tags = ['git', 'changelog']
112-
}
113-
}
123+
// Allows the thin jar to be published, but won't be considered as the java-runtime variant in the module
124+
// This forces Gradle to use the fat jar when applying the plugin
125+
(components.java as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations.runtimeElements) {
126+
skip()
114127
}
115128

116129
publishing {
117130
publications.register('pluginMaven', MavenPublication) {
118-
artifactId = project.name
119-
131+
artifactId = projectArtifactId
120132
changelog.publish it
121133

122134
pom { pom ->
123135
name = projectDisplayName
124136
description = project.description
125137

126-
gradleutils.pom.setGitHubDetails pom
138+
gradleutils.pom.setGitHubDetails(pom)
127139

128140
licenses {
129141
license gradleutils.pom.licenses.LGPLv2_1
130142
}
131143

132-
// TODO [GradleUtils][GU3.0] Re-evaluate active developers in GU 3.0
133144
developers {
134-
developer gradleutils.pom.developers.LexManos
135-
developer gradleutils.pom.developers.SizableShrimp
136-
developer gradleutils.pom.developers.Paint_Ninja
137145
developer gradleutils.pom.developers.Jonathing
146+
developer gradleutils.pom.developers.Paint_Ninja
147+
developer gradleutils.pom.developers.LexManos
138148
}
139149
}
140150
}

gradle.properties

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ org.gradle.caching=true
22
org.gradle.parallel=true
33
org.gradle.configureondemand=true
44

5-
# TODO [GradleUtils][Gradle9] Re-enable config cache in Gradle 9
6-
# Configuration Cache causes issues with plugin publishing.
7-
# Do continue to make our Gradle plugins (GU, FG7, etc.) support it though.
8-
#org.gradle.configuration-cache=true
9-
#org.gradle.configuration-cache.parallel=true
5+
org.gradle.configuration-cache=true
6+
org.gradle.configuration-cache.parallel=true
7+
org.gradle.configuration-cache.problems=warn
108

119
systemProp.org.gradle.unsafe.suppress-gradle-api=true

gradle/gradle-daemon-jvm.properties

Lines changed: 0 additions & 12 deletions
This file was deleted.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
import org.gradle.api.initialization.resolve.RepositoriesMode
2-
31
plugins {
4-
id 'dev.gradleplugins.gradle-plugin-development' version '1.9.0'
52
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.10.0'
63
}
74

85
rootProject.name = 'gradleutils'
96

107
dependencyResolutionManagement {
11-
// Repositories are located in build.gradle for this project
12-
// dev.gradleplugins.groovy-gradle-plugin is bugged and force adds repositories on the project
13-
// so, we can't declare the repositories in here
14-
repositoriesMode = RepositoriesMode.PREFER_PROJECT
8+
repositories {
9+
maven { url = 'https://maven.minecraftforge.net/' }
10+
maven { url = 'https://maven.moddinglegacy.com' } // Gradle API
11+
maven { url = 'https://repo.eclipse.org/content/groups/releases/' }
12+
mavenCentral()
13+
//mavenLocal()
14+
}
1515

1616
versionCatalogs.register('libs') {
17-
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0'
18-
plugin 'gradleutils', 'net.minecraftforge.gradleutils' version '2.5.1'
19-
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1'
20-
plugin 'shadow', 'com.gradleup.shadow' version '9.0.0-beta13'
17+
version 'gradle-javadoc-links', '8.14'
18+
19+
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
20+
plugin 'gradleutils', 'net.minecraftforge.gradleutils' version '2.6.0' // https://plugins.gradle.org/plugin/net.minecraftforge.gradleutils
21+
plugin 'javadoc-links', 'io.freefair.javadoc-links' versionRef 'gradle-javadoc-links' // https://plugins.gradle.org/plugin/io.freefair.javadoc-links
22+
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish
23+
plugin 'shadow', 'com.gradleup.shadow' version '9.0.0-rc3' // https://plugins.gradle.org/plugin/com.gradleup.shadow
2124

2225
// Gradle API
23-
version 'gradle', '7.3'
26+
// TODO [ForgeGradle][FG7][Gradle Api] REMOVE once Gradle publish their own API artifacts
27+
// Original: https://github.com/remal-gradle-api/packages/packages/760197?version=9.0.0
28+
// Mirror: https://repos.moddinglegacy.com/#/modding-legacy/name/remal/gradle-api/gradle-api/9.0.0
29+
version 'gradle', '9.0.0'
30+
library 'gradle', 'name.remal.gradle-api', 'gradle-api' versionRef 'gradle'
31+
library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2'
2432

25-
// Static Analysis
26-
library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2'
33+
// JavaDoc Links Plugin
34+
library 'gradle-javadoc-links', 'io.freefair.javadoc-links', 'io.freefair.javadoc-links.gradle.plugin' versionRef 'gradle-javadoc-links'
2735

2836
// GitHub Actions Workflows
2937
library 'yaml', 'org.yaml', 'snakeyaml' version '2.4'
3038

31-
// Git Version
32-
library 'gitver', 'net.minecraftforge', 'gitversion' version '0.5.2'
33-
34-
// Backwards compatibility
35-
library 'jgit', 'org.eclipse.jgit', 'org.eclipse.jgit' version '7.2.0.202503040940-r'
39+
// Tools
40+
library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.9' // https://files.minecraftforge.net/net/minecraftforge/hash-utils/index.html
41+
library 'utils-download', 'net.minecraftforge', 'download-utils' version '0.3.1' // https://files.minecraftforge.net/net/minecraftforge/download-utils/index.html
42+
bundle 'utils', ['utils-hash', 'utils-download']
3643
}
3744
}

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

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.gradleutils;
6+
7+
import org.gradle.api.DefaultTask;
8+
import org.gradle.api.provider.Property;
9+
import org.gradle.api.provider.ProviderFactory;
10+
import org.gradle.api.reflect.HasPublicType;
11+
import org.gradle.api.reflect.TypeOf;
12+
import org.gradle.api.tasks.Input;
13+
import org.gradle.api.tasks.TaskAction;
14+
15+
import javax.inject.Inject;
16+
17+
// TODO [GradleUtils][TeamCity] Delete this when off of TeamCity
18+
@Deprecated(forRemoval = true)
19+
abstract class ConfigureTeamCity extends DefaultTask implements HasPublicType {
20+
static final String NAME = "configureTeamCity";
21+
22+
@Override
23+
public TypeOf<?> getPublicType() {
24+
// We don't want this task to be configurable, so tell Gradle it's just a default task
25+
return TypeOf.typeOf(DefaultTask.class);
26+
}
27+
28+
@Inject
29+
public ConfigureTeamCity(ProviderFactory providers) {
30+
this.setGroup("Build Setup");
31+
this.setDescription("Prints the marker lines into the log which configure the pipeline. [deprecated]");
32+
this.onlyIf("Only runs on TeamCity, so the TEAMCITY_VERSION environment variable must be set.", task -> providers.environmentVariable("TEAMCITY_VERSION").isPresent());
33+
34+
this.getBuildNumber().convention(providers.provider(() -> this.getProject().getVersion()).map(Object::toString));
35+
}
36+
37+
/** The build number to print, usually the project version. */
38+
protected abstract @Input Property<String> getBuildNumber();
39+
40+
@TaskAction
41+
public void exec() {
42+
this.getLogger().warn("WARNING: Usage of TeamCity is deprecated within Minecraft Forge Minecraft Forge has been gradually moving off of TeamCity and into GitHub Actions. When the migration is fully complete, this task along with its automatic setup will be removed.");
43+
44+
final var buildNumber = this.getBuildNumber().get();
45+
this.getLogger().lifecycle("Setting project variables and parameters.");
46+
System.out.printf("##teamcity[buildNumber '%s']%n", buildNumber);
47+
System.out.printf("##teamcity[setParameter name='env.PUBLISHED_JAVA_ARTIFACT_VERSION' value='%s']%n", buildNumber);
48+
}
49+
}

0 commit comments

Comments
 (0)