Skip to content

Commit aeb8946

Browse files
committed
Merge branch 'dev'
2 parents b7da835 + c1ef9d2 commit aeb8946

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1458
-905
lines changed

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ repositories {
3333
name = "Fabric"
3434
url = uri("https://maven.fabricmc.net/")
3535
}
36-
gradlePluginPortal()
3736
mavenCentral()
37+
gradlePluginPortal()
3838
}
3939

4040
plugins {
@@ -49,7 +49,8 @@ plugins {
4949

5050
// Publishing to Maven Central
5151
alias(libs.plugins.jreleaser)
52-
id("maven-publish")
52+
`maven-publish`
53+
// For generating the gradle plugin marker pom
5354
alias(libs.plugins.gradle.plugin.publish)
5455
}
5556

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
group = dev.aoqia.leaf
22
name = loom
33
description = The Gradle plugin for Leaf (fabric fork)
4-
version = 0.5.1
4+
version = 0.6.0
55
url = https://github.com/aoqia194/leaf-loom
66

77
kotlin.stdlib.default.dependency = false

gradle/test.libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mockito = "5.14.2"
66
java-debug = "0.52.0"
77
mixin = "0.15.5+mixin.0.8.7"
88

9-
gradle-nightly = "8.14-20250208001853+0000"
9+
gradle-nightly = "8.14-20250225001625+0000"
1010
leaf-loader = "1.2.0"
1111
leaf-installer = "1.0.1"
1212

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/dev/aoqia/leaf/loom/build/mixin/AnnotationProcessorInvoker.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.gradle.api.artifacts.Configuration;
4646
import org.gradle.api.artifacts.ConfigurationContainer;
4747
import org.gradle.api.tasks.SourceSet;
48+
import org.gradle.api.tasks.TaskProvider;
4849

4950
/**
5051
* Normally javac invokes annotation processors, but when the scala or kapt plugin are installed they will want to
@@ -61,13 +62,13 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
6162

6263
protected final Project project;
6364
protected final MixinExtension mixinExtension;
64-
protected final Map<SourceSet, T> invokerTasks;
65+
protected final Map<SourceSet, TaskProvider<T>> invokerTasks;
6566
private final LoomGradleExtension loomExtension;
6667
private final String name;
6768
private final Collection<Configuration> apConfigurations;
6869

6970
protected AnnotationProcessorInvoker(
70-
Project project, Collection<Configuration> apConfigurations, Map<SourceSet, T> invokerTasks, String name) {
71+
Project project, Collection<Configuration> apConfigurations, Map<SourceSet, TaskProvider<T>> invokerTasks, String name) {
7172
this.project = project;
7273
this.loomExtension = LoomGradleExtension.get(project);
7374
this.mixinExtension = loomExtension.getMixin();
@@ -88,7 +89,7 @@ public void configureMixin() {
8889

8990
if (!IdeaUtils.isIdeaSync()) {
9091
for (Configuration processorConfig : apConfigurations) {
91-
project.getLogger().info("Adding mixin to classpath of AP config: " + processorConfig.getName());
92+
project.getLogger().info("Adding mixin to classpath of AP config: {}", processorConfig.getName());
9293
// Pass named MC classpath to mixin AP classpath
9394
processorConfig.extendsFrom(
9495
configs.getByName(Constants.Configurations.LOADER_DEPENDENCIES),
@@ -102,8 +103,8 @@ public void configureMixin() {
102103
}
103104
}
104105

105-
for (Map.Entry<SourceSet, T> entry : invokerTasks.entrySet()) {
106-
passMixinArguments(entry.getValue(), entry.getKey());
106+
for (Map.Entry<SourceSet, TaskProvider<T>> entry : invokerTasks.entrySet()) {
107+
entry.getValue().configure(t -> passMixinArguments(t, entry.getKey()));
107108
}
108109
}
109110

src/main/java/dev/aoqia/leaf/loom/build/mixin/GroovyApInvoker.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,38 @@
2323
*/
2424
package dev.aoqia.leaf.loom.build.mixin;
2525

26-
import com.google.common.collect.ImmutableList;
2726
import java.io.File;
2827
import java.util.Map;
29-
import java.util.Objects;
3028
import java.util.stream.Collectors;
29+
3130
import dev.aoqia.leaf.loom.LoomGradleExtension;
3231
import dev.aoqia.leaf.loom.extension.MixinExtension;
32+
33+
import com.google.common.collect.ImmutableList;
3334
import org.gradle.api.Project;
3435
import org.gradle.api.tasks.SourceSet;
36+
import org.gradle.api.tasks.TaskProvider;
3537
import org.gradle.api.tasks.compile.GroovyCompile;
3638

3739
public class GroovyApInvoker extends AnnotationProcessorInvoker<GroovyCompile> {
3840
public GroovyApInvoker(Project project) {
39-
super(project, ImmutableList.of(), getInvokerTasks(project), AnnotationProcessorInvoker.GROOVY);
41+
super(project, ImmutableList.of(), getInvokerTasks(project),
42+
AnnotationProcessorInvoker.GROOVY);
4043
}
4144

42-
private static Map<SourceSet, GroovyCompile> getInvokerTasks(Project project) {
45+
private static Map<SourceSet, TaskProvider<GroovyCompile>> getInvokerTasks(Project project) {
4346
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
44-
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.GROOVY)
45-
.collect(Collectors.toMap(
46-
Map.Entry::getKey, entry -> Objects.requireNonNull((GroovyCompile) entry.getValue())));
47+
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.GROOVY, GroovyCompile.class)
48+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
4749
}
4850

4951
@Override
50-
protected void passArgument(GroovyCompile compileTask, String key, String value) {
51-
compileTask.getOptions().getCompilerArgs().add("-A" + key + "=" + value);
52+
protected File getRefmapDestinationDir(GroovyCompile task) {
53+
return task.getDestinationDirectory().getAsFile().get();
5254
}
5355

5456
@Override
55-
protected File getRefmapDestinationDir(GroovyCompile task) {
56-
return task.getDestinationDirectory().getAsFile().get();
57+
protected void passArgument(GroovyCompile compileTask, String key, String value) {
58+
compileTask.getOptions().getCompilerArgs().add("-A" + key + "=" + value);
5759
}
5860
}

src/main/java/dev/aoqia/leaf/loom/build/mixin/JavaApInvoker.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,36 @@
2525

2626
import java.io.File;
2727
import java.util.Map;
28-
import java.util.Objects;
2928
import java.util.stream.Collectors;
29+
3030
import dev.aoqia.leaf.loom.LoomGradleExtension;
3131
import dev.aoqia.leaf.loom.extension.MixinExtension;
32+
3233
import org.gradle.api.Project;
3334
import org.gradle.api.tasks.SourceSet;
35+
import org.gradle.api.tasks.TaskProvider;
3436
import org.gradle.api.tasks.compile.JavaCompile;
3537

3638
public class JavaApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
3739
public JavaApInvoker(Project project) {
38-
super(
39-
project,
40-
AnnotationProcessorInvoker.getApConfigurations(
41-
project, SourceSet::getAnnotationProcessorConfigurationName),
42-
getInvokerTasks(project),
43-
AnnotationProcessorInvoker.JAVA);
40+
super(project, AnnotationProcessorInvoker.getApConfigurations(project,
41+
SourceSet::getAnnotationProcessorConfigurationName), getInvokerTasks(project),
42+
AnnotationProcessorInvoker.JAVA);
4443
}
4544

46-
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
45+
private static Map<SourceSet, TaskProvider<JavaCompile>> getInvokerTasks(Project project) {
4746
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
48-
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
49-
.collect(Collectors.toMap(
50-
Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
47+
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA, JavaCompile.class)
48+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
5149
}
5250

5351
@Override
54-
protected void passArgument(JavaCompile compileTask, String key, String value) {
55-
compileTask.getOptions().getCompilerArgs().add("-A" + key + "=" + value);
52+
protected File getRefmapDestinationDir(JavaCompile task) {
53+
return task.getDestinationDirectory().getAsFile().get();
5654
}
5755

5856
@Override
59-
protected File getRefmapDestinationDir(JavaCompile task) {
60-
return task.getDestinationDirectory().getAsFile().get();
57+
protected void passArgument(JavaCompile compileTask, String key, String value) {
58+
compileTask.getOptions().getCompilerArgs().add("-A" + key + "=" + value);
6159
}
6260
}

src/main/java/dev/aoqia/leaf/loom/build/mixin/KaptApInvoker.java

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,26 @@
3131
import java.util.Map;
3232
import java.util.Objects;
3333
import java.util.stream.Collectors;
34-
import kotlin.Unit;
34+
3535
import dev.aoqia.leaf.loom.LoomGradleExtension;
3636
import dev.aoqia.leaf.loom.extension.MixinExtension;
37+
38+
import kotlin.Unit;
3739
import org.gradle.api.Project;
3840
import org.gradle.api.tasks.SourceSet;
41+
import org.gradle.api.tasks.TaskProvider;
3942
import org.gradle.api.tasks.compile.JavaCompile;
4043
import org.jetbrains.kotlin.gradle.plugin.KaptExtension;
4144

4245
public class KaptApInvoker extends AnnotationProcessorInvoker<JavaCompile> {
43-
private final KaptExtension kaptExtension = project.getExtensions().getByType(KaptExtension.class);
46+
private final KaptExtension kaptExtension = project.getExtensions()
47+
.getByType(KaptExtension.class);
4448
// Refmap will be written to here with mixin, then moved after JavaCompile to the correct place
4549
private final File dummyRefmapDirectory;
4650

4751
public KaptApInvoker(Project project) {
48-
super(
49-
project,
50-
AnnotationProcessorInvoker.getApConfigurations(project, KaptApInvoker::getKaptConfigurationName),
51-
getInvokerTasks(project),
52-
"Kotlin");
52+
super(project, AnnotationProcessorInvoker.getApConfigurations(project,
53+
KaptApInvoker::getKaptConfigurationName), getInvokerTasks(project), "Kotlin");
5354

5455
try {
5556
dummyRefmapDirectory = Files.createTempDirectory("temp_refmap").toFile();
@@ -63,69 +64,77 @@ public KaptApInvoker(Project project) {
6364
kaptExtension.setIncludeCompileClasspath(false);
6465
}
6566

66-
private static Map<SourceSet, JavaCompile> getInvokerTasks(Project project) {
67+
private static Map<SourceSet, TaskProvider<JavaCompile>> getInvokerTasks(Project project) {
6768
MixinExtension mixin = LoomGradleExtension.get(project).getMixin();
68-
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA)
69-
.collect(Collectors.toMap(
70-
Map.Entry::getKey, entry -> Objects.requireNonNull((JavaCompile) entry.getValue())));
69+
return mixin.getInvokerTasksStream(AnnotationProcessorInvoker.JAVA, JavaCompile.class)
70+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
71+
}
72+
73+
// Pulled out from the internal class:
74+
// https://github.com/JetBrains/kotlin/blob/33a0ec9b4f40f3d6f1f96b2db504ade4c2fafe03/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/Kapt3KotlinGradleSubplugin.kt#L92
75+
private static String getKaptConfigurationName(SourceSet sourceSet) {
76+
String sourceSetName = sourceSet.getName();
77+
78+
if (!sourceSetName.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
79+
return "kapt" +
80+
(sourceSetName.substring(0, 1).toUpperCase() + sourceSetName.substring(1));
81+
}
82+
83+
return "kapt";
7184
}
7285

7386
@Override
7487
public void configureMixin() {
7588
super.configureMixin();
7689

77-
for (Map.Entry<SourceSet, JavaCompile> entry : invokerTasks.entrySet()) {
78-
// Kapt only allows specifying javac args to all annotation processors at once. So we need to specify some
90+
for (Map.Entry<SourceSet, TaskProvider<JavaCompile>> entry : invokerTasks.entrySet()) {
91+
// Kapt only allows specifying javac args to all annotation processors at once. So we
92+
// need to specify some
7993
// dummy
80-
// target location for the refmap and then move it to the correct place for each sourceset
81-
JavaCompile task = entry.getValue();
82-
SourceSet sourceSet = entry.getKey();
83-
task.doLast(t -> {
84-
try {
85-
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet))
94+
// target location for the refmap and then move it to the correct place for each
95+
// sourceset
96+
entry.getValue().configure(task -> {
97+
SourceSet sourceSet = entry.getKey();
98+
task.doLast(t -> {
99+
try {
100+
String refmapName = Objects.requireNonNull(
101+
MixinExtension.getMixinInformationContainer(sourceSet))
86102
.refmapNameProvider()
87103
.get();
88-
Path src = Paths.get(getRefmapDestination(task, refmapName));
89-
Path dest = Paths.get(
90-
task.getDestinationDirectory().get().getAsFile().toString(), refmapName);
91-
92-
// Possible that no mixin annotations exist
93-
if (Files.exists(src)) {
94-
project.getLogger().info("Copying refmap from " + src + " to " + dest);
95-
Files.move(src, dest);
104+
Path src = Paths.get(getRefmapDestination(task, refmapName));
105+
Path dest = Paths.get(
106+
task.getDestinationDirectory().get().getAsFile().toString(),
107+
refmapName);
108+
109+
// Possible that no mixin annotations exist
110+
if (Files.exists(src)) {
111+
project.getLogger().info("Copying refmap from {} to {}", src, dest);
112+
Files.move(src, dest);
113+
}
114+
} catch (IOException e) {
115+
project.getLogger()
116+
.warn("Could not move refmap generated by kapt for task {}", task, e);
96117
}
97-
} catch (IOException e) {
98-
project.getLogger().warn("Could not move refmap generated by kapt for task " + task, e);
99-
}
118+
});
100119
});
101120
}
102121
}
103122

104-
// Pulled out from the internal class:
105-
// https://github.com/JetBrains/kotlin/blob/33a0ec9b4f40f3d6f1f96b2db504ade4c2fafe03/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/Kapt3KotlinGradleSubplugin.kt#L92
106-
private static String getKaptConfigurationName(SourceSet sourceSet) {
107-
String sourceSetName = sourceSet.getName();
108-
109-
if (!sourceSetName.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
110-
return "kapt" + (sourceSetName.substring(0, 1).toUpperCase() + sourceSetName.substring(1));
111-
}
112-
113-
return "kapt";
123+
@Override
124+
protected File getRefmapDestinationDir(JavaCompile task) {
125+
return dummyRefmapDirectory;
114126
}
115127

116128
@Override
117129
protected void passArgument(JavaCompile compileTask, String key, String value) {
118-
// Note: this MUST be run early on, before kapt uses this data, and there is only a point to setting the value
130+
// Note: this MUST be run early on, before kapt uses this data, and there is only a
131+
// point
132+
// to setting the value
119133
// once since
120134
// kapt shares the options with all java compilers
121135
kaptExtension.arguments(args -> {
122136
args.arg(key, value);
123137
return Unit.INSTANCE;
124138
});
125139
}
126-
127-
@Override
128-
protected File getRefmapDestinationDir(JavaCompile task) {
129-
return dummyRefmapDirectory;
130-
}
131140
}

0 commit comments

Comments
 (0)