Skip to content

Commit ba99d5f

Browse files
committed
Cleanup and Git Version Plugin API change
- Small buildscript cleanup. - The `GitVersionExtension` class is now the public facing API for Git Version in the Gradle plugin. - Use `gitversion.tagOffset` instead of `gitversion.version.tagOffset`. - Many parts of Git Version API such as getting a directory now use Gradle's `DirectoryProperty` when applicable. - If configuration cache is not requested, Git Version will not disable reading from the system's Git config. - PomUtils cleanup. - `Developers` renamed to `developers` (now lowercase) to match `licenses`. The uppercase field will be removed in GU 3.0. - Licenses now use the SPDX identifier as the name and `repo` as the distribution, as recommended by the [reference spec](https://maven.apache.org/pom.html#Licenses). - All-around code cleanup. - Documentation is not a focus this time.
1 parent 6936fdd commit ba99d5f

19 files changed

+452
-293
lines changed

build.gradle

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
id 'java-gradle-plugin'
35
id 'groovy'
46
id 'idea'
7+
id 'eclipse'
58
id 'maven-publish'
69
id 'net.minecraftforge.licenser' version '1.1.1'
7-
id 'com.gradle.plugin-publish' version '1.2.1'
810
id 'net.minecraftforge.gradleutils'
11+
id 'com.gradle.plugin-publish' version '1.3.1'
912
id 'com.gradleup.shadow' version '8.3.6'
1013
}
1114

15+
final projectDisplayName = 'Forge Gradle Utilities'
16+
description = 'Small collection of utilities for standardizing MinecraftForge gradle scripts'
1217
group = 'net.minecraftforge'
13-
version = gitversion.version.tagOffset
18+
version = gitversion.tagOffset
19+
1420
println "Version: $version"
1521

1622
apply from: 'build_shared.gradle'
1723

18-
tasks.withType(GroovyCompile).configureEach {
19-
groovyOptions.optimizationOptions.indy = true
20-
}
21-
2224
license {
2325
header = file('LICENSE-header.txt')
2426
newLine = false
2527
exclude '** /*.properties'
2628
}
2729

28-
jar {
30+
tasks.named('jar', Jar) {
2931
archiveClassifier = 'thin'
3032
}
3133

32-
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
34+
tasks.named('shadowJar', ShadowJar) {
3335
enableRelocation = true
3436
archiveClassifier = null
3537
relocationPrefix = 'net.minecraftforge.gradleutils.shadow'
@@ -41,7 +43,7 @@ groovydoc.use = true
4143
// javadocJar is created after evaluation, so we need to configure it here
4244
afterEvaluate {
4345
tasks.named('javadocJar', Jar) {
44-
dependsOn groovydoc
46+
dependsOn tasks.named('groovydoc', Groovydoc)
4547
from groovydoc.destinationDir
4648
}
4749
}
@@ -51,24 +53,45 @@ changelog {
5153
publishAll = false
5254
}
5355

56+
gradlePlugin {
57+
website = gitversion.url
58+
vcsUrl = "${gitversion.url}.git"
59+
plugins {
60+
gradleutils {
61+
id = 'net.minecraftforge.gradleutils'
62+
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
63+
displayName = projectDisplayName
64+
description = project.description
65+
tags.set(['minecraftforge'])
66+
}
67+
changelog {
68+
id = 'net.minecraftforge.changelog'
69+
implementationClass = 'net.minecraftforge.gradleutils.changelog.ChangelogPlugin'
70+
displayName = 'Git Changelog'
71+
description = 'Creates a changelog text file based on git history using GitVersion'
72+
tags.set(['git', 'changelog'])
73+
}
74+
}
75+
}
76+
5477
publishing {
5578
publications.register('pluginMaven', MavenPublication) {
5679
changelog.publish(it)
5780
pom { pom ->
58-
artifactId = 'gradleutils'
59-
name = 'Gradle Utils'
60-
description = 'Used by MinecraftForge projects as a util library for Gradle buildscripts'
81+
artifactId = project.name
82+
name = projectDisplayName
83+
description = project.description
6184

6285
gradleutils.pom.gitHubDetails = pom
6386

6487
license gradleutils.pom.licenses.LGPLv2_1
6588

6689
// TODO [GradleUtils] Re-evaluate active developers in GU 3.0
6790
developers {
68-
developer gradleutils.pom.Developers.LexManos
69-
developer gradleutils.pom.Developers.SizableShrimp
70-
developer gradleutils.pom.Developers.Paint_Ninja
71-
developer gradleutils.pom.Developers.Jonathing
91+
developer gradleutils.pom.developers.LexManos
92+
developer gradleutils.pom.developers.SizableShrimp
93+
developer gradleutils.pom.developers.Paint_Ninja
94+
developer gradleutils.pom.developers.Jonathing
7295
}
7396
}
7497
}

buildSrc/build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ plugins {
44

55
apply from: '../build_shared.gradle'
66

7-
sourceSets {
8-
main {
9-
groovy {
10-
srcDirs = ['../src/main/groovy']
7+
sourceSets.main.groovy.srcDirs = ['../src/main/groovy']
8+
9+
gradlePlugin {
10+
plugins {
11+
gradleutils {
12+
id = 'net.minecraftforge.gradleutils'
13+
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
1114
}
1215
}
1316
}

build_shared.gradle

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
21
java {
32
// GitVersion requires Java 17
43
toolchain.languageVersion = JavaLanguageVersion.of(17)
54
withSourcesJar()
65
}
76

7+
tasks.withType(GroovyCompile).configureEach {
8+
groovyOptions.optimizationOptions.indy = true
9+
}
10+
811
repositories {
912
maven { url = 'https://maven.minecraftforge.net' }
1013
maven { url = 'https://repo.eclipse.org/content/groups/releases/' }
@@ -28,24 +31,3 @@ dependencies {
2831
// TODO - Deprecated git utilities, remove in 3.0
2932
implementation libs.jgit
3033
}
31-
32-
gradlePlugin {
33-
website = 'https://github.com/MinecraftForge/GradleUtils'
34-
vcsUrl = 'https://github.com/MinecraftForge/GradleUtils.git'
35-
plugins {
36-
gradleutils {
37-
id = 'net.minecraftforge.gradleutils'
38-
implementationClass = 'net.minecraftforge.gradleutils.GradleUtilsPlugin'
39-
displayName = 'Forge Gradle Utilities'
40-
description = 'Small collection of utilities for standardizing our gradle scripts'
41-
tags.set(['minecraftforge'])
42-
}
43-
changelog {
44-
id = 'net.minecraftforge.changelog'
45-
implementationClass = 'net.minecraftforge.gradleutils.changelog.ChangelogPlugin'
46-
displayName = 'Git Changelog'
47-
description = 'Creates a changelog text file based on git history using GitVersion'
48-
tags.set(['git', 'changelog'])
49-
}
50-
}
51-
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ org.gradle.caching=true
22
org.gradle.parallel=true
33
org.gradle.configureondemand=true
44
org.gradle.configuration-cache=true
5+
org.gradle.configuration-cache.parallel=true
6+
org.gradle.configuration-cache.problems=warn

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ plugins {
22
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
33
}
44

5-
rootProject.name = 'GradleUtils'
5+
rootProject.name = 'gradleutils'
66

77
apply from: 'settings_shared.gradle'

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import javax.inject.Inject
1818
/**
1919
* This task prints the marker lines into the log which configure the pipeline.
2020
*
21-
* @deprecated Will be removed once Forge moves off of TeamCity
21+
* @deprecated Will be removed once Forge moves off of TeamCity.
2222
*/
2323
@CompileStatic
2424
@Deprecated(forRemoval = true)
@@ -33,26 +33,24 @@ abstract class ConfigureTeamCity extends DefaultTask {
3333
project.tasks.register(name, ConfigureTeamCity)
3434
}
3535

36-
@Inject
37-
abstract ProviderFactory getProviders()
36+
@Inject abstract ProviderFactory getProviders()
3837

3938
ConfigureTeamCity() {
4039
this.description = 'Prints the marker lines into the log which configure the pipeline. [deprecated]'
4140
this.onlyIf('Only runs on TeamCity, so the TEAMCITY_VERSION environment variable must be set.') { GradleUtils.hasEnvVar('TEAMCITY_VERSION', this.providers).get() }
4241

43-
this.version.convention this.providers.provider { this.project.version?.toString() }
42+
this.buildNumber.convention this.providers.provider { this.project.version?.toString() }
4443
}
4544

46-
/** The version string to print, usually the {@linkplain Project#getVersion() project version}. */
47-
@Input
48-
abstract Property<String> getVersion()
45+
/** The build number to print, usually the project version. */
46+
abstract @Input Property<String> getBuildNumber()
4947

5048
@TaskAction
5149
void exec() {
5250
this.logger.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.'
5351

5452
this.logger.lifecycle 'Setting project variables and parameters.'
55-
println "##teamcity[buildNumber '${this.version.get()}']"
56-
println "##teamcity[setParameter name='env.PUBLISHED_JAVA_ARTIFACT_VERSION' value='${this.version.get()}']"
53+
println "##teamcity[buildNumber '${this.buildNumber.get()}']"
54+
println "##teamcity[setParameter name='env.PUBLISHED_JAVA_ARTIFACT_VERSION' value='${this.buildNumber.get()}']"
5755
}
5856
}

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

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package net.minecraftforge.gradleutils
66

77
import groovy.transform.CompileStatic
8+
import groovy.transform.PackageScope
89
import net.minecraftforge.gradleutils.gitversion.GitVersionExtension
910
import org.gradle.api.DefaultTask
1011
import org.gradle.api.Project
@@ -24,60 +25,39 @@ import javax.inject.Inject
2425

2526
/**
2627
* This task generates the GitHub Actions workflow file for the project, respecting declared subprojects in Git Version.
27-
* <p>
28-
* This can be very useful when creating new projects or subprojects.
28+
* <p>This can be very useful when creating new projects or subprojects.</p>
2929
*/
3030
@CompileStatic
3131
abstract class GenerateActionsWorkflow extends DefaultTask {
3232
public static final String NAME = 'generateActionsWorkflow'
3333

34-
static TaskProvider<GenerateActionsWorkflow> register(Project project) {
35-
register(project, NAME)
34+
@PackageScope static TaskProvider<GenerateActionsWorkflow> register(Project project) {
35+
project.tasks.register(NAME, GenerateActionsWorkflow)
3636
}
3737

38-
static TaskProvider<GenerateActionsWorkflow> register(Project project, String name) {
39-
project.tasks.register(name, GenerateActionsWorkflow)
40-
}
41-
42-
@Inject
43-
abstract ProviderFactory getProviders()
38+
@Inject abstract ProviderFactory getProviders()
4439

4540
GenerateActionsWorkflow() {
4641
this.description = 'Generates the GitHub Actions workflow file for the project, respecting declared subprojects in Git Version.'
4742

4843
this.outputFile.convention this.project.rootProject.layout.projectDirectory.file(this.providers.provider { "build_${this.project.name}.yaml" })
4944

5045
this.projectName.convention this.providers.provider { this.project.name }
51-
this.branch.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).version.info.branch }
52-
this.localPath.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).version.projectPath }
53-
this.paths.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).version.subprojectPaths.collect { "!${it}/**".toString() } }
46+
this.branch.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).info.branch }
47+
this.localPath.convention this.project.extensions.getByType(GitVersionExtension).projectPath
48+
this.paths.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).subprojectPaths.get().collect { "!${it}/**".toString() } }
5449
this.gradleJavaVersion.convention 21
5550
this.sharedActionsBranch.convention 'v0'
5651
}
5752

58-
@OutputFile
59-
abstract RegularFileProperty getOutputFile()
60-
61-
@Input
62-
abstract Property<String> getProjectName()
63-
64-
@Input
65-
@Optional
66-
abstract Property<String> getBranch()
67-
68-
@Input
69-
@Optional
70-
abstract Property<String> getLocalPath()
71-
72-
@Input
73-
@Optional
74-
abstract ListProperty<String> getPaths()
75-
76-
@Input
77-
abstract Property<Integer> getGradleJavaVersion()
53+
abstract @OutputFile RegularFileProperty getOutputFile()
7854

79-
@Input
80-
abstract Property<String> getSharedActionsBranch()
55+
abstract @Input Property<String> getProjectName()
56+
abstract @Input @Optional Property<String> getBranch()
57+
abstract @Input @Optional Property<String> getLocalPath()
58+
abstract @Input @Optional ListProperty<String> getPaths()
59+
abstract @Input Property<Integer> getGradleJavaVersion()
60+
abstract @Input Property<String> getSharedActionsBranch()
8161

8262
@TaskAction
8363
void exec() throws IOException {

0 commit comments

Comments
 (0)