Skip to content

Commit 40ccd71

Browse files
committed
Change attribute application strategy
Bumped the Gradle plugin to 5.0 due to public API breaking change. Also a logical breaking change: access-transformed dependencies are only present in the `compileClasspath`, `runtimeClasspath`, and `annotationProcessor` resolvable configurations. I will add API in the future to be able to add destination configurations for AT'd dependencies.
1 parent 17613ca commit 40ccd71

File tree

14 files changed

+123
-93
lines changed

14 files changed

+123
-93
lines changed

at-gradle-demo/gradle.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
org.gradle.caching=true
2+
org.gradle.parallel=true
3+
org.gradle.configureondemand=true
4+
5+
org.gradle.configuration-cache=true
6+
org.gradle.configuration-cache.parallel=true
7+
org.gradle.configuration-cache.problems=warn
8+
9+
net.minecraftforge.gradleutils.compilation.defaults=true

at-gradle-demo/settings.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ pluginManagement {
22
includeBuild '../at-gradle'
33

44
repositories {
5-
//mavenLocal()
65
mavenCentral()
76
gradlePluginPortal()
87
maven { url = 'https://maven.minecraftforge.net' }
8+
//mavenLocal()
99
}
1010
}
1111

1212
plugins {
1313
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
14-
id 'net.minecraftforge.gradleutils' version '3.2.6'
14+
id 'net.minecraftforge.gradleutils' version '3.3.11'
1515
}
1616

1717
rootProject.name = 'at-gradle-demo'

at-gradle/build.gradle

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
id 'idea'
88
id 'eclipse'
99
id 'maven-publish'
10-
id 'io.freefair.javadoc-links'
10+
//id 'io.freefair.javadoc-links'
1111
id 'net.minecraftforge.gradleutils'
1212
alias libs.plugins.gitversion
1313
alias libs.plugins.changelog
@@ -16,32 +16,19 @@ plugins {
1616
alias libs.plugins.shadow
1717
}
1818

19-
final projectDisplayName = 'AccessTransformers Gradle Plugin'
19+
gradleutils.displayName = 'AccessTransformers Gradle Plugin'
2020
description = 'Enables Gradle projects to use AccessTransformers on dependencies with minimal hassle.'
2121
base.archivesName = 'accesstransformers-gradle'
2222
group = 'net.minecraftforge'
2323
version = gitversion.tagOffset
2424

25-
println "Version: $version"
26-
2725
java {
2826
toolchain.languageVersion = JavaLanguageVersion.of(17)
2927
withSourcesJar()
3028
withJavadocJar()
3129
}
3230

33-
configurations {
34-
// Applies the "Gradle Plugin API Version" attribute to configuration
35-
// This was added in Gradle 7, gives consumers useful errors if they are on an old version
36-
def applyGradleVersionAttribute = { Configuration configuration ->
37-
configuration.attributes {
38-
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named(GradlePluginApiVersion, libs.versions.gradle.get()))
39-
}
40-
}
41-
42-
named(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
43-
named(ShadowJavaPlugin.SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME, applyGradleVersionAttribute)
44-
}
31+
gradleutils.pluginDevDefaults(configurations, libs.versions.gradle)
4532

4633
dependencies {
4734
// Static Analysis
@@ -57,15 +44,6 @@ dependencies {
5744
implementation libs.bundles.utils
5845
}
5946

60-
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
61-
// Publish Plugin: https://github.com/gradle/plugin-portal-requests/issues/260
62-
// Shadow: https://github.com/GradleUp/shadow/pull/1422
63-
afterEvaluate { project ->
64-
project.configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME) { compileOnly ->
65-
compileOnly.dependencies.remove(project.dependencies.gradleApi())
66-
}
67-
}
68-
6947
license {
7048
header = rootProject.file('../LICENSE-header.txt')
7149
newLine = false
@@ -84,11 +62,6 @@ tasks.named('shadowJar', ShadowJar) {
8462

8563
tasks.withType(Javadoc).configureEach {
8664
javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(24) }
87-
88-
options { StandardJavadocDocletOptions options ->
89-
options.windowTitle = projectDisplayName + project.version
90-
options.tags 'apiNote:a:API Note:', 'implNote:a:Implementation Note:', 'implSpec:a:Implementation Requirements:'
91-
}
9265
}
9366

9467
changelog {
@@ -102,7 +75,7 @@ gradlePlugin {
10275
plugins.register('accesstransformers') {
10376
id = 'net.minecraftforge.accesstransformers'
10477
implementationClass = 'net.minecraftforge.accesstransformers.gradle.AccessTransformersPlugin'
105-
displayName = projectDisplayName
78+
displayName = gradleutils.displayName
10679
description = project.description
10780
tags = ['minecraftforge']
10881
}
@@ -118,7 +91,7 @@ publishing {
11891
gradleutils.promote(it)
11992

12093
pom { pom ->
121-
name = projectDisplayName
94+
name = gradleutils.displayName
12295
description = project.description
12396

12497
gradleutils.pom.addRemoteDetails(pom)
@@ -133,6 +106,3 @@ publishing {
133106
}
134107
}
135108
}
136-
137-
idea.module { downloadSources = downloadJavadoc = true }
138-
eclipse.classpath { downloadSources = downloadJavadoc = true }

at-gradle/gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ org.gradle.configuration-cache.parallel=true
77
org.gradle.configuration-cache.problems=warn
88

99
systemProp.org.gradle.unsafe.suppress-gradle-api=true
10+
11+
net.minecraftforge.gradleutils.publishing.use-base-archives-name=true
12+
net.minecraftforge.gradleutils.ide.automatic.sources=true
13+
net.minecraftforge.gradleutils.compilation.defaults=true
14+
15+
net.minecraftforge.gitversion.log.version=true

at-gradle/settings.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ plugins {
44
// NOTE: We need to load this into the classpath before GradleUtils for the service to load correctly
55
id 'io.freefair.javadoc-links' version '8.14' apply false // https://plugins.gradle.org/plugin/io.freefair.javadoc-links
66

7-
id 'net.minecraftforge.gradleutils' version '3.2.6' // https://plugins.gradle.org/plugin/net.minecraftforge.gradleutils
7+
id 'net.minecraftforge.gradleutils' version '3.3.11' // https://plugins.gradle.org/plugin/net.minecraftforge.gradleutils
88
}
99

1010
rootProject.name = 'at-gradle'
1111

1212
dependencyResolutionManagement {
1313
repositories {
14-
//mavenLocal()
1514
mavenCentral()
1615
maven gradleutils.forgeMaven
1716
maven { url = 'https://maven.moddinglegacy.com/maven' } // Gradle API
17+
//mavenLocal()
1818
}
1919

2020
//@formatter:off
2121
versionCatalogs.register('libs') {
2222
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
23-
plugin 'gitversion', 'net.minecraftforge.gitversion' version '3.0.3' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
24-
plugin 'changelog', 'net.minecraftforge.changelog' version '3.0.3' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
23+
plugin 'gitversion', 'net.minecraftforge.gitversion' version '3.1.0' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
24+
plugin 'changelog', 'net.minecraftforge.changelog' version '3.1.1' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
2525
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish
2626
plugin 'shadow', 'com.gradleup.shadow' version '9.0.2' // https://plugins.gradle.org/plugin/com.gradleup.shadow
2727

@@ -35,7 +35,7 @@ dependencyResolutionManagement {
3535
library 'gradle', 'name.remal.gradle-api', 'gradle-api' versionRef 'gradle'
3636

3737
// GradleUtils Shared Base
38-
library 'gradleutils-shared', 'net.minecraftforge', 'gradleutils-shared' version '3.2.6'
38+
library 'gradleutils-shared', 'net.minecraftforge', 'gradleutils-shared' version '3.3.11'
3939

4040
// Utils
4141
library 'utils-hash', 'net.minecraftforge', 'hash-utils' version '0.1.9'

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersContainerImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.gradle.api.file.RegularFileProperty;
2727
import org.gradle.api.logging.LogLevel;
2828
import org.gradle.api.model.ObjectFactory;
29+
import org.gradle.api.plugins.ExtensionAware;
30+
import org.gradle.api.plugins.JavaPluginExtension;
2931
import org.gradle.api.provider.ListProperty;
3032
import org.gradle.api.provider.Property;
3133
import org.gradle.api.provider.Provider;
@@ -151,8 +153,9 @@ public Dependency dep(
151153
Closure<?> closure
152154
) {
153155
return this.project.getDependencies().create(dependencyNotation, closure.compose(Closures.<Dependency>unaryOperator(dependency -> {
154-
if (dependency instanceof HasConfigurableAttributes<?> d) {
155-
d.attributes(a -> a.attribute(this.attribute, true));
156+
if (dependency instanceof HasConfigurableAttributes<?>) {
157+
var ext = ((ExtensionAware) dependency).getExtensions().getExtraProperties();
158+
ext.set("__at_attribute", this.attribute);
156159
} else {
157160
this.problems.reportIllegalTargetDependency(dependency);
158161
}
@@ -208,7 +211,7 @@ public OptionsImpl(Project project) {
208211
this.classpath.from(plugin.getTool(Tools.ACCESSTRANSFORMERS));
209212
//this.mainClass.convention(Tools.ACCESSTRANSFORMERS.getMainClass());
210213
this.javaLauncher.convention(Util.launcherFor(project, Tools.ACCESSTRANSFORMERS.getJavaVersion()));
211-
this.args.convention(Constants.AT_DEFAULT_ARGS);
214+
this.args.convention(Constants.ACCESSTRANSFORMERS_DEFAULT_ARGS);
212215
}
213216

214217
@Override

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersExtension.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
*/
55
package net.minecraftforge.accesstransformers.gradle;
66

7-
import groovy.lang.Closure;
8-
import groovy.lang.DelegatesTo;
9-
import groovy.transform.stc.ClosureParams;
10-
import groovy.transform.stc.SimpleType;
11-
import net.minecraftforge.gradleutils.shared.Closures;
127
import org.gradle.api.Action;
138
import org.gradle.api.attributes.Attribute;
149
import org.jetbrains.annotations.ApiStatus;

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersExtensionImpl.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
import groovy.transform.stc.ClosureParams;
1010
import groovy.transform.stc.SimpleType;
1111
import org.gradle.api.Action;
12+
import org.gradle.api.InvalidUserDataException;
13+
import org.gradle.api.NamedDomainObjectProvider;
1214
import org.gradle.api.Project;
1315
import org.gradle.api.artifacts.Dependency;
16+
import org.gradle.api.artifacts.DependencyScopeConfiguration;
17+
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
18+
import org.gradle.api.artifacts.ModuleDependency;
19+
import org.gradle.api.artifacts.ModuleVersionSelector;
20+
import org.gradle.api.artifacts.ProjectDependency;
1421
import org.gradle.api.attributes.Attribute;
22+
import org.gradle.api.plugins.ExtensionAware;
23+
import org.gradle.api.plugins.JavaPluginExtension;
1524
import org.gradle.api.provider.Provider;
25+
import org.gradle.api.provider.ProviderConvertible;
1626
import org.jetbrains.annotations.Nullable;
1727

1828
import javax.inject.Inject;
@@ -26,6 +36,50 @@ abstract class AccessTransformersExtensionImpl implements AccessTransformersExte
2636
@Inject
2737
public AccessTransformersExtensionImpl(Project project) {
2838
this.project = project;
39+
project.afterEvaluate(AccessTransformersExtensionImpl::finish);
40+
}
41+
42+
@SuppressWarnings({"DataFlowIssue", "unchecked"})
43+
private static void finish(Project project) {
44+
var configurations = project.getConfigurations();
45+
NamedDomainObjectProvider<DependencyScopeConfiguration> accessTransformersDependencyConstraints;
46+
{
47+
NamedDomainObjectProvider<DependencyScopeConfiguration> c;
48+
try {
49+
c = configurations.dependencyScope("accessTransformersDependencyConstraints", configuration -> {
50+
configuration.setDescription("Dependency constraints to enforce access transformer usage.");
51+
});
52+
} catch (InvalidUserDataException e) {
53+
c = configurations.named("accessTransformerDependencyConstraints", DependencyScopeConfiguration.class);
54+
}
55+
accessTransformersDependencyConstraints = c;
56+
}
57+
58+
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().forEach(sourceSet -> {
59+
var dependencies = Util.collect(configurations, sourceSet, true, dependency -> {
60+
var ext = ((ExtensionAware) dependency).getExtensions().getExtraProperties();
61+
return ext.has("__at_attribute");
62+
});
63+
64+
dependencies.forEach(dependency -> {
65+
var ext = ((ExtensionAware) dependency).getExtensions().getExtraProperties();
66+
Object dependencyNotation = dependency;
67+
if (dependencyNotation instanceof ProviderConvertible<?>) {
68+
dependencyNotation = ((ProviderConvertible<?>) dependencyNotation).asProvider();
69+
}
70+
if (dependencyNotation instanceof Provider<?>) {
71+
dependencyNotation = ((Provider<?>) dependencyNotation).get();
72+
}
73+
if (!(dependencyNotation instanceof MinimalExternalModuleDependency) && !(dependencyNotation instanceof ProjectDependency) && dependencyNotation instanceof ModuleVersionSelector module) {
74+
dependencyNotation = module.getModule().toString();
75+
}
76+
77+
accessTransformersDependencyConstraints.get().getDependencyConstraints().add(project.getDependencies().getConstraints().create(dependencyNotation, constraint -> {
78+
constraint.attributes(a -> a.attribute((Attribute<Boolean>) ext.get("__at_attribute"), true));
79+
}));
80+
Util.forClasspathConfigurations(configurations, sourceSet, c -> c.extendsFrom(accessTransformersDependencyConstraints.get()));
81+
});
82+
});
2983
}
3084

3185
@Override

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersProblems.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public AccessTransformersProblems() {
2525
void reportIllegalTargetDependency(Dependency dependency) {
2626
var dependencyToString = Util.toString(dependency);
2727
this.getLogger().error("ERROR: Cannot access transform target dependency: {}", dependencyToString);
28-
this.getReporter().report(this.id("access-transformer-illegal-dependency-target", "Cannot access transform target dependency"), spec -> spec
28+
this.report("access-transformer-illegal-dependency-target", "Cannot access transform target dependency", spec -> spec
2929
.details("""
3030
Cannot apply Access Transformers to a dependency that cannot be configured with attributes.
3131
Dependency: %s"""
@@ -48,7 +48,7 @@ RuntimeException accessTransformerConfigNotDefined(Exception e, Attribute<Boolea
4848
}
4949

5050
RuntimeException accessTransformerConfigMissing(Exception e, Attribute<Boolean> attribute, String atFilePath) {
51-
return this.getReporter().throwing(e, this.id("access-transformer-config-missing", "Access transformer config file not found"), spec -> spec
51+
return this.throwing(e, "access-transformer-config-missing", "Access transformer config file not found", spec -> spec
5252
.details("""
5353
The access transformer cannot transform the input artifact because the configuration file could not be found.
5454
Attribute: %s
@@ -60,7 +60,7 @@ RuntimeException accessTransformerConfigMissing(Exception e, Attribute<Boolean>
6060
}
6161

6262
RuntimeException accessTransformerConfigUnreadable(Throwable e, Attribute<Boolean> attribute, String atFilePath) {
63-
return this.getReporter().throwing(e, this.id("access-transformer-config-unreadable", "Access transformer config file not read"), spec -> spec
63+
return this.throwing(e, "access-transformer-config-unreadable", "Access transformer config file not read", spec -> spec
6464
.details("""
6565
The access transformer cannot transform the input artifact because the configuration file could not be read.
6666
This may be due to insufficient file permissions or a corrupted file.
@@ -72,7 +72,7 @@ RuntimeException accessTransformerConfigUnreadable(Throwable e, Attribute<Boolea
7272
}
7373

7474
RuntimeException accessTransformerConfigEmpty(Exception e, Attribute<Boolean> attribute, String atFilePath) {
75-
return this.getReporter().throwing(e, this.id("access-transformer-config-empty", "Access transformer config missing or empty"), spec -> spec
75+
return this.throwing(e, "access-transformer-config-empty", "Access transformer config missing or empty", spec -> spec
7676
.details("""
7777
The access transformer cannot transform the input artifact because the configuration file is empty or blank.
7878
Attribute: %s
@@ -85,7 +85,7 @@ RuntimeException accessTransformerConfigEmpty(Exception e, Attribute<Boolean> at
8585

8686
void reportAccessTransformerCannotValidateOutput(Exception e, File inJar, File atFile, File outJar, File logFile) {
8787
this.getLogger().warn("WARNING: Access transformer completed, but failed to validate the output. Output jar: {}", outJar.getAbsolutePath());
88-
this.getReporter().report(this.id("access-transformer-output-validation-failed", "Failed to validate the access transformed output"), spec -> spec
88+
this.report("access-transformer-output-validation-failed", "Failed to validate the access transformed output", spec -> spec
8989
.details("""
9090
The access transformer completed the transformation, but failed to validate the output.
9191
While the output JAR may have been created successfully, it cannot be determined if any transformations were made.
@@ -103,7 +103,7 @@ void reportAccessTransformerCannotValidateOutput(Exception e, File inJar, File a
103103
}
104104

105105
RuntimeException accessTransformerCannotWriteOutput(Exception e, Path output) {
106-
return this.getReporter().throwing(e, this.id("access-transformer-output-write-failed", "Failed to write the access transformed output"), spec -> spec
106+
return this.throwing(e, "access-transformer-output-write-failed", "Failed to write the access transformed output", spec -> spec
107107
.details("""
108108
The access transformer completed the transformation, but failed to write the output to Gradle.
109109
This could potentially be caused the lack of read/write permissions in the build folder or Gradle caches (`~/.gradle`).
@@ -116,7 +116,7 @@ RuntimeException accessTransformerCannotWriteOutput(Exception e, Path output) {
116116

117117
void reportAccessTransformerOutputIdentical(File inJar, File atFile, File outJar, File logFile) {
118118
this.getLogger().warn("WARNING: Access transformer completed, but the output bytes are the same as the input. Output jar: {}", outJar.getAbsolutePath());
119-
this.getReporter().report(this.id("access-transformer-output-identical", "Access transformer output identical to input"), spec -> spec
119+
this.report("access-transformer-output-identical", "Access transformer output identical to input", spec -> spec
120120
.details("""
121121
The access transformer completed the transformation, but the output bytes are the same as the input.
122122
This could potentially be caused by an empty or invalid access transformer configuration.
@@ -132,7 +132,7 @@ void reportAccessTransformerOutputIdentical(File inJar, File atFile, File outJar
132132
}
133133

134134
RuntimeException accessTransformerFailed(RuntimeException e, File inJar, File atFile, File logFile) {
135-
return this.getReporter().throwing(e, this.id("access-transformer-failed", "Access transformer failed"), spec -> spec
135+
return this.throwing(e, "access-transformer-failed", "Access transformer failed", spec -> spec
136136
.details("""
137137
The access transformer failed to apply the transformations.
138138
This could potentially be caused by an invalid access transformer configuration.

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/Constants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
final class Constants {
1010
private Constants() { }
1111

12-
static final List<String> AT_DEFAULT_ARGS = List.of(
12+
static final String ACCESSTRANSFORMERS_NAME = "accesstransformers";
13+
static final String ACCESSTRANSFORMERS_VERSION = "8.2.2";
14+
static final String ACCESSTRANSFORMERS_DOWNLOAD_URL = "https://maven.minecraftforge.net/net/minecraftforge/accesstransformers/" + ACCESSTRANSFORMERS_VERSION + "/accesstransformers-" + ACCESSTRANSFORMERS_VERSION + "-fatjar.jar";
15+
static final int ACCESSTRANSFORMERS_MIN_JAVA = 8;
16+
static final String ACCESSTRANSFORMERS_MAIN = "net.minecraftforge.accesstransformer.TransformerProcessor";
17+
18+
static final List<String> ACCESSTRANSFORMERS_DEFAULT_ARGS = List.of(
1319
"--inJar", "{inJar}",
1420
"--atFile", "{atFile}",
1521
"--outJar", "{outJar}",

0 commit comments

Comments
 (0)