Skip to content

3.0 - API restructuring and Deprecation removals #23

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'net.minecraftforge.licenser' version '1.1.1'
id 'net.minecraftforge.gradleutils'
id 'net.minecraftforge.licenser' version '1.2.0'
id 'net.minecraftforge.gradleutils' version '2.5.1'
id 'com.gradle.plugin-publish' version '1.3.1'
id 'com.gradleup.shadow' version '8.3.6'
}
Expand All @@ -19,7 +19,41 @@ version = gitversion.tagOffset

println "Version: $version"

apply from: 'build_shared.gradle'
java {
// GitVersion requires Java 17
toolchain.languageVersion = JavaLanguageVersion.of(17)
withSourcesJar()
}

tasks.withType(GroovyCompile).configureEach {
groovyOptions.optimizationOptions.indy = true
}

repositories {
maven gradleutils.forgeMaven
maven { url = 'https://repo.eclipse.org/content/groups/releases/' }
mavenCentral()
mavenLocal()
}

configurations {
implementation {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
}

dependencies {
compileOnly libs.groovy

// GitHub Actions Workflows
implementation libs.yaml

// Git Version
implementation libs.gitver

// TODO - Deprecated git utilities, remove in 3.0
implementation libs.jgit
}

license {
header = file('LICENSE-header.txt')
Expand Down Expand Up @@ -76,9 +110,10 @@ gradlePlugin {

publishing {
publications.register('pluginMaven', MavenPublication) {
changelog.publish(it)
artifactId = project.name
changelog.publish it

pom { pom ->
artifactId = project.name
name = projectDisplayName
description = project.description

Expand Down
16 changes: 0 additions & 16 deletions buildSrc/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion buildSrc/settings.gradle

This file was deleted.

33 changes: 0 additions & 33 deletions build_shared.gradle

This file was deleted.

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ org.gradle.configureondemand=true
# TODO [GradleUtils][Gradle9] Re-enable config cache in Gradle 9
# Configuration Cache comes with too many bugs to be worth the trouble.
# Do continue to make our Gradle plugins (GU, FG7, etc.) support it though.
org.gradle.configuration-cache=false
org.gradle.configuration-cache.parallel=false
#org.gradle.configuration-cache=true
#org.gradle.configuration-cache.parallel=true
18 changes: 17 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ plugins {

rootProject.name = 'gradleutils'

apply from: 'settings_shared.gradle'
dependencyResolutionManagement {
versionCatalogs {
libs {
// Included with Gradle API, but manually declared to view sources and JavaDoc links
library 'groovy', 'org.codehaus.groovy', 'groovy-all' version '3.0.22'

// GitHub Actions Workflows
library('yaml', 'org.yaml', 'snakeyaml').version('2.4')

// Git Version
library('gitver', 'net.minecraftforge', 'git-version').version('0.4.2')

// TODO - Deprecated git utilities, remove in 3.0
library('jgit', 'org.eclipse.jgit', 'org.eclipse.jgit').version('7.2.0.202503040940-r')
}
}
}
14 changes: 0 additions & 14 deletions settings_shared.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package net.minecraftforge.gradleutils

import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import groovy.transform.PackageScopeTarget
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.provider.Property
Expand All @@ -15,31 +17,18 @@ import org.gradle.api.tasks.TaskProvider

import javax.inject.Inject

/**
* This task prints the marker lines into the log which configure the pipeline.
*
* @deprecated Will be removed once Forge moves off of TeamCity.
*/
// TODO [GradleUtils][TeamCity] Delete this when off of TeamCity
@CompileStatic
@Deprecated(forRemoval = true)
@PackageScope([PackageScopeTarget.CLASS, PackageScopeTarget.FIELDS])
abstract class ConfigureTeamCity extends DefaultTask {
public static final String NAME = 'configureTeamCity'

static TaskProvider<ConfigureTeamCity> register(Project project) {
register(project, NAME)
}

static TaskProvider<ConfigureTeamCity> register(Project project, String name) {
project.tasks.register(name, ConfigureTeamCity)
}

@Inject abstract ProviderFactory getProviders()
static final String NAME = 'configureTeamCity'

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

this.buildNumber.convention this.providers.provider { this.project.version?.toString() }
this.buildNumber.convention providers.provider { this.project.version?.toString() }
}

/** The build number to print, usually the project version. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package net.minecraftforge.gradleutils

import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import groovy.transform.PackageScopeTarget
import net.minecraftforge.gradleutils.gitversion.GitVersionExtension
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
Expand All @@ -17,52 +17,50 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml

import javax.inject.Inject
import java.nio.charset.StandardCharsets
import java.nio.file.Files

/**
* This task generates the GitHub Actions workflow file for the project, respecting declared subprojects in Git Version.
* <p>This can be very useful when creating new projects or subprojects.</p>
*/
@CompileStatic
@PackageScope([PackageScopeTarget.CLASS, PackageScopeTarget.FIELDS])
abstract class GenerateActionsWorkflow extends DefaultTask {
public static final String NAME = 'generateActionsWorkflow'
static final String NAME = 'generateActionsWorkflow'

@PackageScope static TaskProvider<GenerateActionsWorkflow> register(Project project) {
project.tasks.register(NAME, GenerateActionsWorkflow)
}

@Inject abstract ProviderFactory getProviders()

GenerateActionsWorkflow() {
@Inject
GenerateActionsWorkflow(ProviderFactory providers) {
this.group = 'Build Setup'
this.description = 'Generates the GitHub Actions workflow file for the project, respecting declared subprojects in Git Version.'

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

this.projectName.convention this.providers.provider { this.project.name }
this.branch.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).info.branch }
this.projectName.convention providers.provider { this.project.name }
this.branch.convention providers.provider { this.project.extensions.getByType(GitVersionExtension).info.branch }
this.localPath.convention this.project.extensions.getByType(GitVersionExtension).projectPath
this.paths.convention this.providers.provider { this.project.extensions.getByType(GitVersionExtension).subprojectPaths.get().collect { "!${it}/**".toString() } }
this.paths.convention providers.provider { this.project.extensions.getByType(GitVersionExtension).subprojectPaths.get().collect { "!${it}/**".toString() } }
this.gradleJavaVersion.convention 21
this.sharedActionsBranch.convention 'v0'

this.outputFile.convention this.project.rootProject.layout.projectDirectory.dir('.github/workflows').file(providers.provider { "build_${this.projectName.get()}.yaml" })
}

abstract @OutputFile RegularFileProperty getOutputFile()

abstract @Input Property<String> getProjectName()
abstract @Input @Optional Property<String> getBranch()
abstract @Input @Optional Property<String> getLocalPath()
abstract @Input @Optional ListProperty<String> getPaths()
abstract @Optional @Input Property<String> getBranch()
abstract @Optional @Input Property<String> getLocalPath()
abstract @Optional @Input ListProperty<String> getPaths()
abstract @Input Property<Integer> getGradleJavaVersion()
abstract @Input Property<String> getSharedActionsBranch()

@TaskAction
void exec() throws IOException {
var localPath = this.localPath.orNull
var paths = this.paths.getOrElse(Collections.emptyList())
var paths = this.paths.getOrElse Collections.emptyList()

var push = [
'branches': this.branch.getOrElse('master'),
Expand Down Expand Up @@ -105,9 +103,13 @@ abstract class GenerateActionsWorkflow extends DefaultTask {
).dump(yaml).replace("'on':", 'on:')

var file = outputFile.asFile.get()
if (!file.parentFile.exists())
file.parentFile.mkdirs()

file.setText(workflow, 'UTF8')
if (!file.parentFile.exists() && !file.parentFile.mkdirs())
throw new IllegalStateException()

Files.writeString(
file.toPath(),
workflow,
StandardCharsets.UTF_8
)
}
}
Loading