Skip to content

Commit 128d539

Browse files
committed
Consolidate GradleUtilsExtension repos
1 parent 7b5fda3 commit 128d539

File tree

8 files changed

+154
-190
lines changed

8 files changed

+154
-190
lines changed

build.gradle

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin
23
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
3-
import net.minecraftforge.gradleutils.GradleUtilsExtension
44

55
plugins {
66
id 'java-gradle-plugin'
@@ -25,22 +25,13 @@ version = gitversion.tagOffset
2525

2626
println "Version: $version"
2727

28-
// This plugin being applied to settings.gradle first also affects linting in the build.gradle
29-
// https://youtrack.jetbrains.com/issue/IDEA-332061/Gradle-Missing-Code-Completion-Suggestions-for-Settings-Plugins-in-Groovy-DSL
30-
final gradleutils = extensions.getByType(GradleUtilsExtension.ForProject)
31-
3228
java {
3329
toolchain.languageVersion = JavaLanguageVersion.of(17)
3430
withSourcesJar()
3531
withJavadocJar()
3632
}
3733

3834
configurations {
39-
named(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) {
40-
// Fixes a conflict between Git Version's shadowed SLF4J from JGit and Gradle's own loggers
41-
exclude group: 'org.slf4j', module: 'slf4j-api'
42-
}
43-
4435
// Applies the "Gradle Plugin API Version" attribute to configuration
4536
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
4637
def applyGradleVersionAttribute = { Configuration configuration ->
@@ -49,8 +40,8 @@ configurations {
4940
}
5041
}
5142

52-
named('runtimeElements', applyGradleVersionAttribute)
53-
named('shadowRuntimeElements', applyGradleVersionAttribute)
43+
named(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
44+
named(ShadowJavaPlugin.SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
5445
}
5546

5647
dependencies {
@@ -73,7 +64,7 @@ dependencies {
7364
// Shadow: https://github.com/GradleUp/shadow/pull/1422
7465
afterEvaluate { project ->
7566
project.configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME) { compileOnly ->
76-
compileOnly.dependencies.remove project.dependencies.gradleApi()
67+
compileOnly.dependencies.remove(project.dependencies.gradleApi())
7768
}
7869
}
7970

@@ -124,12 +115,6 @@ gradlePlugin {
124115
}
125116
}
126117

127-
// Allows the thin jar to be published, but won't be considered as the java-runtime variant in the module
128-
// This forces Gradle to use the fat jar when applying the plugin
129-
(components.java as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations.runtimeElements) {
130-
skip()
131-
}
132-
133118
publishing {
134119
publications.register('pluginMaven', MavenPublication) {
135120
artifactId = projectArtifactId

settings.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222

2323
// https://plugins.gradle.org/plugin/net.minecraftforge.gradleutils
2424
// Gradle utilities for Minecraft Forge projects.
25-
id 'net.minecraftforge.gradleutils' version '3.0.0-beta.13'
25+
id 'net.minecraftforge.gradleutils' version '3.0.0-beta.15'
2626
}
2727

2828
// Known bug with Groovy DSL in IntelliJ, it's never getting fixed
@@ -40,14 +40,14 @@ dependencyResolutionManagement {
4040
}
4141

4242
versionCatalogs.register('libs') {
43-
version 'gradle-gitversion', '3.0.0-beta.9'
43+
version 'gradle-gitversion', '3.0.0-beta.12'
4444
version 'gradle-javadoc-links', '8.14'
4545

46-
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
47-
plugin 'gitversion', 'net.minecraftforge.gitversion' versionRef 'gradle-gitversion' // https://plugins.gradle.org/plugin/net.minecraftforge.gitversion
48-
plugin 'changelog', 'net.minecraftforge.changelog' versionRef 'gradle-gitversion' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
49-
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish
50-
plugin 'shadow', 'com.gradleup.shadow' version '9.0.0-rc3' // https://plugins.gradle.org/plugin/com.gradleup.shadow
46+
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
47+
plugin 'gitversion', 'net.minecraftforge.gitversion' versionRef 'gradle-gitversion' // https://plugins.gradle.org/plugin/net.minecraftforge.gitversion
48+
plugin 'changelog', 'net.minecraftforge.changelog' versionRef 'gradle-gitversion' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
49+
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish
50+
plugin 'shadow', 'com.gradleup.shadow' version '9.0.1' // https://plugins.gradle.org/plugin/com.gradleup.shadow
5151

5252
// Gradle API
5353
// TODO [ForgeGradle][FG7][Gradle Api] REMOVE once Gradle publish their own API artifacts

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtension.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import groovy.lang.Closure;
88
import org.gradle.api.Action;
99
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
10+
import org.gradle.api.file.Directory;
11+
import org.gradle.api.provider.Provider;
12+
13+
import java.io.File;
1014

1115
/// Contains various utilities for working with Gradle scripts.
1216
///
@@ -49,4 +53,71 @@ public sealed interface GradleUtilsExtension permits GradleUtilsExtensionInterna
4953
* </code></pre>
5054
*/
5155
Action<MavenArtifactRepository> minecraftLibsMaven = GradleUtilsExtensionInternal.minecraftLibsMaven;
56+
57+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
58+
/// publishing block.
59+
///
60+
/// **Important:** The following environment variables must be set for this to work:
61+
/// - `MAVEN_USER`: Containing the username to use for authentication
62+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
63+
///
64+
/// The following environment variables are optional:
65+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
66+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
67+
/// no longer supported as of 3.0.0.
68+
///
69+
/// If the required environment variables are not present, the output Maven will be a local folder named `repo` on
70+
/// the root of the [build directory][org.gradle.initialization.layout.BuildLayout#getRootDirectory()].
71+
///
72+
/// If the `MAVEN_URL_RELEASE` variable is not set, the Forge releases repository will be used
73+
/// (`https://maven.minecraftforge.net/releases`).
74+
///
75+
/// @return The closure
76+
default Action<MavenArtifactRepository> getPublishingForgeMaven() {
77+
return getPublishingForgeMaven("https://maven.minecraftforge.net/releases");
78+
}
79+
80+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
81+
/// publishing block.
82+
///
83+
/// **Important:** The following environment variables must be set for this to work:
84+
/// - `MAVEN_USER`: Containing the username to use for authentication
85+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
86+
///
87+
/// The following environment variables are optional:
88+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
89+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
90+
/// no longer supported as of 3.0.0.
91+
///
92+
/// If the required environment variables are not present, the output Maven will be a local folder named `repo` on
93+
/// the root of the [build directory][org.gradle.initialization.layout.BuildLayout#getRootDirectory()].
94+
///
95+
/// If the `MAVEN_URL_RELEASE` variable is not set, the passed in fallback URL will be used for the release
96+
/// repository.
97+
///
98+
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
99+
/// @return The closure
100+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint);
101+
102+
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
103+
/// publishing block.
104+
/// **Important:** The following environment variables must be set for this to work:
105+
/// - `MAVEN_USER`: Containing the username to use for authentication
106+
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
107+
///
108+
/// The following environment variables are optional:
109+
/// - `MAVEN_URL(_RELEASE)`: Containing the URL to use for the release repository
110+
/// - Please note that since Forge does not have a snapshot repository, snapshot maven publishing via GradleUtils is
111+
/// no longer supported as of 3.0.0.
112+
///
113+
/// If the required environment variables are not present, the output Maven will be set to the given default
114+
/// folder.
115+
///
116+
/// If the `MAVEN_URL(_RELEASE)` variable is not set, the passed in fallback URL will be used for the release
117+
/// repository.
118+
///
119+
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
120+
/// @param defaultFolder The default folder if the required maven information is not set
121+
/// @return The closure
122+
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, Provider<? extends Directory> defaultFolder);
52123
}

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtensionForProject.java

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
*/
55
package net.minecraftforge.gradleutils;
66

7-
import groovy.lang.Closure;
8-
import org.gradle.api.Action;
9-
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
10-
11-
import java.io.File;
12-
137
/// The GradleUtils extension for [projects][org.gradle.api.Project], which include additional utilities that are only
148
/// available for them.
159
///
@@ -20,113 +14,10 @@
2014
/// - Register the `configureTeamCity` task to the project for working with TeamCity CI pipelines.
2115
///
2216
/// @see GradleUtilsExtension
23-
sealed public interface GradleUtilsExtensionForProject extends GradleUtilsExtension permits GradleUtilsExtensionInternal.ForProject {
17+
public sealed interface GradleUtilsExtensionForProject extends GradleUtilsExtension permits GradleUtilsExtensionInternal.ForProject {
2418
/// Utilities for working with a [org.gradle.api.publish.maven.MavenPom] for publishing artifacts.
2519
///
2620
/// @return The POM utilities
2721
/// @see PomUtils
2822
PomUtils getPom();
29-
30-
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
31-
/// publishing block.
32-
///
33-
/// This closure respects the current project's version in regard to publishing to a release or snapshot
34-
/// repository.
35-
///
36-
/// **Important:** The following environment variables must be set for this to work:
37-
/// - `MAVEN_USER`: Containing the username to use for authentication
38-
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
39-
///
40-
/// The following environment variables are optional:
41-
/// - `MAVEN_URL_RELEASE`: Containing the URL to use for the release repository
42-
/// - `MAVEN_URL_SNAPSHOT`: Containing the URL to use for the snapshot repository
43-
///
44-
/// If the required environment variables are not present, the output Maven will be a local folder named `repo` on
45-
/// the root of the [project directory][org.gradle.api.file.ProjectLayout#getProjectDirectory()].
46-
///
47-
/// If the `MAVEN_URL_RELEASE` variable is not set, the Forge releases repository will be used
48-
/// (`https://maven.minecraftforge.net/releases`).
49-
///
50-
/// @return The closure
51-
default Action<MavenArtifactRepository> getPublishingForgeMaven() {
52-
return getPublishingForgeMaven("https://maven.minecraftforge.net/releases");
53-
}
54-
55-
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
56-
/// publishing block.
57-
///
58-
/// This closure respects the current project's version in regard to publishing to a release or snapshot
59-
/// repository.
60-
///
61-
/// **Important:** The following environment variables must be set for this to work:
62-
/// - `MAVEN_USER`: Containing the username to use for authentication
63-
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
64-
///
65-
/// The following environment variables are optional:
66-
/// - `MAVEN_URL_RELEASE`: Containing the URL to use for the release repository
67-
/// - `MAVEN_URL_SNAPSHOT`: Containing the URL to use for the snapshot repository
68-
///
69-
/// If the required environment variables are not present, the output Maven will be a local folder named `repo` on
70-
/// the root of the [project directory][org.gradle.api.file.ProjectLayout#getProjectDirectory()].
71-
///
72-
/// If the `MAVEN_URL_RELEASE` variable is not set, the passed in fallback URL will be used for the release
73-
/// repository.
74-
///
75-
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
76-
/// @return The closure
77-
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint);
78-
79-
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
80-
/// publishing block.
81-
///
82-
/// This closure respects the current project's version in regard to publishing to a release or snapshot
83-
/// repository.
84-
///
85-
/// **Important:** The following environment variables must be set for this to work:
86-
/// - `MAVEN_USER`: Containing the username to use for authentication
87-
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
88-
///
89-
/// The following environment variables are optional:
90-
/// - `MAVEN_URL_RELEASE`: Containing the URL to use for the release repository
91-
/// - `MAVEN_URL_SNAPSHOT`: Containing the URL to use for the snapshot repository
92-
///
93-
/// If the required environment variables are not present, the output Maven will be set to the given default
94-
/// folder.
95-
///
96-
/// If the `MAVEN_URL_RELEASE` variable is not set, the passed in fallback URL will be used for the release
97-
/// repository.
98-
///
99-
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
100-
/// @param defaultFolder The default folder if the required maven information is not set
101-
/// @return The closure
102-
default Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, File defaultFolder) {
103-
return getPublishingForgeMaven(fallbackPublishingEndpoint, defaultFolder, new File(defaultFolder.getAbsoluteFile().getParentFile(), "snapshots"));
104-
}
105-
106-
/// Get a configuring closure to be passed into [org.gradle.api.artifacts.dsl.RepositoryHandler#maven(Closure)] in a
107-
/// publishing block.
108-
///
109-
/// This closure respects the current project's version in regard to publishing to a release or snapshot
110-
/// repository.
111-
///
112-
/// **Important:** The following environment variables must be set for this to work:
113-
/// - `MAVEN_USER`: Containing the username to use for authentication
114-
/// - `MAVEN_PASSWORD`: Containing the password to use for authentication
115-
///
116-
/// The following environment variables are optional:
117-
/// - `MAVEN_URL_RELEASE`: Containing the URL to use for the release repository
118-
/// - `MAVEN_URL_SNAPSHOT`: Containing the URL to use for the snapshot repository
119-
///
120-
/// If the required environment variables are not present, the output Maven will be set to the given default
121-
/// folder.
122-
///
123-
/// If the `MAVEN_URL_RELEASE` variable is not set, the passed in fallback URL will be used for the release
124-
/// repository.
125-
///
126-
/// @param fallbackPublishingEndpoint The fallback URL for the release repository
127-
/// @param defaultFolder The default folder if the required maven information is not set
128-
/// @param defaultSnapshotFolder The default folder for the snapshot repository if the required maven
129-
/// information is not set
130-
/// @return The closure
131-
Action<MavenArtifactRepository> getPublishingForgeMaven(String fallbackPublishingEndpoint, File defaultFolder, File defaultSnapshotFolder);
13223
}

0 commit comments

Comments
 (0)