Skip to content

Commit 9c45f84

Browse files
committed
Split off shared base into its own subproject
Note: This is NOT another plugin. This week, a lot of work has been spent merging the common code between FG7, FD7, and GU3 into one shared package that all of them can extend off of. Originally this was just a package within GU3 itself, but this will inevitably cause problems with plugins that may need to interface with GU3 itself (not the shared base). My solution was to create 'gradleutils-shared', a project that holds only this common code and nothing else. The point is for our Gradle projects to shadow in this code so that it doesn't have an arbitrary requirement on GU3 being present in the classpath. I am publishing 'gradleutils-shared' in a way so that the shadow jar is the only one that can be consumed. Project dependencies cannot read module files, however, so the GU3 buildscript itself has a workaround for it.
1 parent 128d539 commit 9c45f84

File tree

19 files changed

+198
-26
lines changed

19 files changed

+198
-26
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish Shared Plugin Base
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
paths:
7+
- 'gradleutils-shared/**'
8+
- '!.github/workflows/**'
9+
- '!README.md'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@v0
17+
with:
18+
java: 17
19+
gradle_tasks: ':gradleutils-shared:check :gradleutils-shared:publish'
20+
artifact_name: 'gradleutils-shared'
21+
project_path: 'gradleutils-shared'
22+
secrets:
23+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
24+
PROMOTE_ARTIFACT_WEBHOOK: ${{ secrets.PROMOTE_ARTIFACT_WEBHOOK }}
25+
PROMOTE_ARTIFACT_USERNAME: ${{ secrets.PROMOTE_ARTIFACT_USERNAME }}
26+
PROMOTE_ARTIFACT_PASSWORD: ${{ secrets.PROMOTE_ARTIFACT_PASSWORD }}
27+
MAVEN_USER: ${{ secrets.MAVEN_USER }}
28+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
29+
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
30+
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}

.github/workflows/publish.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ name: Publish
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [ 'main' ]
6+
paths-ignore:
7+
- 'gradleutils-shared/**'
8+
- '.github/workflows/**'
9+
- 'README.md'
610

711
permissions:
812
contents: read
@@ -12,8 +16,8 @@ jobs:
1216
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@v0
1317
with:
1418
java: 17
15-
gradle_tasks: "check publish publishPlugins"
16-
artifact_name: "gradleutils"
19+
gradle_tasks: ':gradleutils-shared:check :check :publish :publishPlugins'
20+
artifact_name: 'gradleutils'
1721
secrets:
1822
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
1923
PROMOTE_ARTIFACT_WEBHOOK: ${{ secrets.PROMOTE_ARTIFACT_WEBHOOK }}

build.gradle

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ java {
3232
}
3333

3434
configurations {
35+
// NOTE: If you are making a new Gradle plugin, do not copy this block!
36+
configureEach {
37+
resolutionStrategy.dependencySubstitution {
38+
// NOTE: We build this in this repo, but enforce the module using a dependency substitution
39+
// That way, new plugins can effectively copy this buildscript just without this section
40+
// The "shadowed" attribute is declared here since project dependencies do not read the published module file
41+
substitute module('net.minecraftforge:gradleutils-shared') using variant(project(':gradleutils-shared')) {
42+
attributes {
43+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.SHADOWED))
44+
}
45+
}
46+
}
47+
}
48+
3549
// Applies the "Gradle Plugin API Version" attribute to configuration
3650
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
3751
def applyGradleVersionAttribute = { Configuration configuration ->
@@ -45,17 +59,20 @@ configurations {
4559
}
4660

4761
dependencies {
62+
// Static Analysis
63+
compileOnly libs.nulls
64+
4865
// Gradle API
49-
compileOnly libs.bundles.gradle
66+
compileOnly libs.gradle
67+
68+
// GradleUtils Shared Base
69+
implementation libs.gradleutils.shared
5070

5171
// JavaDoc Links Plugin
5272
compileOnly libs.gradle.javadoc.links
5373

5474
// GitHub Actions Workflows
5575
implementation libs.yaml
56-
57-
// Tools
58-
implementation libs.bundles.utils
5976
}
6077

6178
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
@@ -144,3 +161,4 @@ publishing {
144161
}
145162

146163
idea.module { downloadSources = downloadJavadoc = true }
164+
eclipse.classpath { downloadSources = downloadJavadoc = true }

gradleutils-shared/build.gradle

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin
3+
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
4+
5+
plugins {
6+
id 'java-library'
7+
id 'idea'
8+
id 'eclipse'
9+
id 'maven-publish'
10+
id 'io.freefair.javadoc-links'
11+
id 'net.minecraftforge.gradleutils'
12+
alias libs.plugins.licenser
13+
alias libs.plugins.gitversion
14+
alias libs.plugins.shadow
15+
}
16+
17+
final projectDisplayName = 'Minecraft Forge Shared Plugin Base'
18+
final projectArtifactId = base.archivesName = 'gradleutils-shared'
19+
description = 'The shared base used by all of Minecraft Forge\'s Gradle plugins'
20+
group = 'net.minecraftforge'
21+
version = gitversion.tagOffset
22+
23+
println "Version: $version"
24+
25+
java {
26+
toolchain.languageVersion = JavaLanguageVersion.of(17)
27+
withSourcesJar()
28+
withJavadocJar()
29+
}
30+
31+
configurations {
32+
// Applies the "Gradle Plugin API Version" attribute to configuration
33+
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
34+
def applyGradleVersionAttribute = { Configuration configuration ->
35+
configuration.attributes {
36+
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.asProvider().get()))
37+
}
38+
}
39+
40+
named(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
41+
named(ShadowJavaPlugin.SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
42+
}
43+
44+
dependencies {
45+
// Static Analysis
46+
compileOnly libs.nulls
47+
48+
// Gradle API
49+
compileOnly libs.gradle
50+
51+
// Tools
52+
implementation libs.bundles.utils
53+
}
54+
55+
license {
56+
header = rootProject.file('LICENSE-header.txt')
57+
newLine = false
58+
exclude '**/*.properties'
59+
}
60+
61+
tasks.named('jar', Jar) {
62+
archiveClassifier = 'thin'
63+
}
64+
65+
tasks.named('shadowJar', ShadowJar) {
66+
enableAutoRelocation = true
67+
archiveClassifier = null
68+
relocationPrefix = 'net.minecraftforge.gradleutils.shared.shadow'
69+
}
70+
71+
tasks.withType(Javadoc).configureEach {
72+
javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(24) }
73+
74+
options { StandardJavadocDocletOptions options ->
75+
options.windowTitle = projectDisplayName + project.version
76+
options.tags 'apiNote:a:API Note:', 'implNote:a:Implementation Note:', 'implSpec:a:Implementation Requirements:'
77+
}
78+
}
79+
80+
// Allows the thin jar to be published, but won't be considered as the java-runtime variant in the module
81+
// This forces Gradle to use the fat jar when applying the plugin
82+
(components.java as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations.runtimeElements) {
83+
skip()
84+
}
85+
86+
publishing {
87+
publications.register('mavenJava', MavenPublication) {
88+
from components.java
89+
artifactId = projectArtifactId
90+
91+
pom { pom ->
92+
name = projectDisplayName
93+
description = project.description
94+
95+
gradleutils.pom.addRemoteDetails(pom)
96+
97+
licenses {
98+
license gradleutils.pom.licenses.LGPLv2_1
99+
}
100+
101+
developers {
102+
developer gradleutils.pom.developers.Jonathing
103+
}
104+
}
105+
}
106+
107+
repositories {
108+
maven gradleutils.publishingForgeMaven
109+
}
110+
}
111+
112+
idea.module { downloadSources = downloadJavadoc = true }
113+
eclipse.classpath { downloadSources = downloadJavadoc = true }

src/main/groovy/net/minecraftforge/gradleutils/shared/Closures.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/Closures.java

File renamed without changes.

src/main/groovy/net/minecraftforge/gradleutils/shared/EnhancedPlugin.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/EnhancedPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.gradle.api.model.ObjectFactory;
1313
import org.gradle.api.provider.Provider;
1414
import org.gradle.api.provider.ProviderFactory;
15-
import org.gradle.api.tasks.Internal;
1615
import org.jetbrains.annotations.ApiStatus;
1716

1817
import javax.inject.Inject;

src/main/groovy/net/minecraftforge/gradleutils/shared/EnhancedProblems.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/EnhancedProblems.java

File renamed without changes.

src/main/groovy/net/minecraftforge/gradleutils/shared/EnhancedTask.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/EnhancedTask.java

File renamed without changes.

src/main/groovy/net/minecraftforge/gradleutils/shared/Lazy.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/Lazy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/// @apiNote This lazy implementation uses Groovy's [closures][Closure] instead of typical [suppliers][Supplier] or
1818
/// [callables][Callable], as the closure API allows chaining via [Closure#compose(Closure)] and
1919
/// [Closure#andThen(Closure)]. They can still be created using callables.
20-
/// @see Lazy.Actionable
20+
/// @see Actionable
2121
public sealed class Lazy<T> implements Supplier<T>, Callable<T> permits Lazy.Actionable {
2222
/// Creates a simple lazy of the given callable.
2323
///

src/main/groovy/net/minecraftforge/gradleutils/shared/SharedUtil.java renamed to gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/SharedUtil.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,21 @@
88
import groovy.lang.DelegatesTo;
99
import groovy.transform.stc.ClosureParams;
1010
import groovy.transform.stc.FirstParam;
11-
import org.codehaus.groovy.runtime.InvokerHelper;
1211
import org.gradle.api.Action;
1312
import org.gradle.api.Project;
1413
import org.gradle.api.artifacts.Dependency;
1514
import org.gradle.api.artifacts.FileCollectionDependency;
1615
import org.gradle.api.artifacts.ModuleVersionSelector;
17-
import org.gradle.api.plugins.ExtensionAware;
1816
import org.gradle.api.plugins.JavaPluginExtension;
1917
import org.gradle.api.provider.Property;
2018
import org.gradle.api.provider.Provider;
21-
import org.gradle.api.provider.ProviderFactory;
2219
import org.gradle.jvm.toolchain.JavaLanguageVersion;
2320
import org.gradle.jvm.toolchain.JavaLauncher;
2421
import org.gradle.jvm.toolchain.JavaToolchainService;
2522
import org.gradle.jvm.toolchain.JavaToolchainSpec;
26-
import org.jetbrains.annotations.Nullable;
2723

2824
import java.io.File;
2925
import java.io.OutputStream;
30-
import java.util.Objects;
3126

3227
/// Shared utilities for Gradle plugins.
3328
public abstract class SharedUtil {

0 commit comments

Comments
 (0)