Add mixin ap to projects in a "better way" (#144)
* Add mixin ap to projects in a "better way" Signed-off-by: liach <liach@users.noreply.github.com> * Remove obsolete bad code Signed-off-by: liach <liach@users.noreply.github.com> * Use a field in constants instead Signed-off-by: liach <liach@users.noreply.github.com> * String format does not work Signed-off-by: liach <liach@users.noreply.github.com>dev/0.11
parent
458eaabb7e
commit
c8ef934bda
|
@ -47,7 +47,6 @@ dependencies {
|
||||||
implementation ('net.fabricmc:tiny-remapper:0.2.0.56') {
|
implementation ('net.fabricmc:tiny-remapper:0.2.0.56') {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
implementation ('net.fabricmc:fabric-mixin-compile-extensions:0.2.0.3')
|
|
||||||
|
|
||||||
// decompilers
|
// decompilers
|
||||||
implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+')
|
implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+')
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import groovy.util.Node;
|
import groovy.util.Node;
|
||||||
|
@ -40,10 +39,7 @@ import org.gradle.api.Task;
|
||||||
import org.gradle.api.UnknownTaskException;
|
import org.gradle.api.UnknownTaskException;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.Dependency;
|
import org.gradle.api.artifacts.Dependency;
|
||||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
|
|
||||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||||||
import org.gradle.api.artifacts.result.DependencyResult;
|
|
||||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
|
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginConvention;
|
import org.gradle.api.plugins.JavaPluginConvention;
|
||||||
import org.gradle.api.publish.Publication;
|
import org.gradle.api.publish.Publication;
|
||||||
|
@ -199,8 +195,8 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
* Permit to add a Maven repository to a target project.
|
* Permit to add a Maven repository to a target project.
|
||||||
*
|
*
|
||||||
* @param target The garget project
|
* @param target The garget project
|
||||||
* @param name The name of the repository
|
* @param name The name of the repository
|
||||||
* @param url The URL of the repository
|
* @param url The URL of the repository
|
||||||
* @return An object containing the name and the URL of the repository that can be modified later
|
* @return An object containing the name and the URL of the repository that can be modified later
|
||||||
*/
|
*/
|
||||||
public MavenArtifactRepository addMavenRepo(Project target, final String name, final String url) {
|
public MavenArtifactRepository addMavenRepo(Project target, final String name, final String url) {
|
||||||
|
@ -226,42 +222,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
|
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addModule(Project proj, String configuration, DependencyResult module) {
|
|
||||||
if (module instanceof ResolvedDependencyResult) {
|
|
||||||
if (module.getFrom().getId() instanceof ModuleComponentIdentifier) {
|
|
||||||
ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) module.getFrom().getId());
|
|
||||||
String moduleId = mci.getGroup() + ":" + mci.getModule() + ":" + mci.getVersion();
|
|
||||||
proj.getDependencies().add(configuration, proj.getDependencies().module(moduleId));
|
|
||||||
proj.getLogger().debug("Loom addModule " + moduleId + " to " + configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DependencyResult child : ((ResolvedDependencyResult) module).getSelected().getDependencies()) {
|
|
||||||
addModule(proj, configuration, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean findAndAddModule(Project project, String configuration, DependencyResult dep, Predicate<ModuleComponentIdentifier> predicate) {
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
if (dep instanceof ResolvedDependencyResult) {
|
|
||||||
if (dep.getFrom().getId() instanceof ModuleComponentIdentifier) {
|
|
||||||
ModuleComponentIdentifier mci = ((ModuleComponentIdentifier) dep.getFrom().getId());
|
|
||||||
|
|
||||||
if (predicate.test(mci)) {
|
|
||||||
addModule(project, configuration, dep);
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DependencyResult child : ((ResolvedDependencyResult) dep).getSelected().getDependencies()) {
|
|
||||||
findAndAddModule(project, configuration, child, predicate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Minecraft dependencies to compile time.
|
* Add Minecraft dependencies to compile time.
|
||||||
*/
|
*/
|
||||||
|
@ -275,21 +235,7 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
||||||
|
|
||||||
// Add Mixin dependencies
|
// Add Mixin dependencies
|
||||||
Project p = project;
|
project.getDependencies().add(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME, "net.fabricmc:fabric-mixin-compile-extensions:" + Constants.MIXIN_COMPILE_EXTENSIONS_VERSION);
|
||||||
|
|
||||||
while (true) {
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
for (DependencyResult dep : p.getBuildscript().getConfigurations().getByName("classpath").getIncoming().getResolutionResult().getRoot().getDependencies()) {
|
|
||||||
found = findAndAddModule(project, "annotationProcessor", dep, (mci) -> ("net.fabricmc".equals(mci.getGroup()) && "fabric-mixin-compile-extensions".equals(mci.getModule())));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found || AbstractPlugin.isRootProject(p)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = p.getRootProject();
|
|
||||||
}
|
|
||||||
|
|
||||||
project.afterEvaluate(project1 -> {
|
project.afterEvaluate(project1 -> {
|
||||||
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
|
@ -39,9 +39,13 @@ public class Constants {
|
||||||
|
|
||||||
public static final String MOD_COMPILE_CLASSPATH = "modCompileClasspath";
|
public static final String MOD_COMPILE_CLASSPATH = "modCompileClasspath";
|
||||||
public static final String MOD_COMPILE_CLASSPATH_MAPPED = "modCompileClasspathMapped";
|
public static final String MOD_COMPILE_CLASSPATH_MAPPED = "modCompileClasspathMapped";
|
||||||
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of(new RemappedConfigurationEntry("modCompile", "compile", true, "compile"), new RemappedConfigurationEntry("modApi", "api", true, "compile"),
|
public static final List<RemappedConfigurationEntry> MOD_COMPILE_ENTRIES = ImmutableList.of(
|
||||||
new RemappedConfigurationEntry("modImplementation", "implementation", true, "runtime"), new RemappedConfigurationEntry("modRuntime", "runtimeOnly", false, ""),
|
new RemappedConfigurationEntry("modCompile", "compile", true, "compile"),
|
||||||
new RemappedConfigurationEntry("modCompileOnly", "compileOnly", true, ""));
|
new RemappedConfigurationEntry("modApi", "api", true, "compile"),
|
||||||
|
new RemappedConfigurationEntry("modImplementation", "implementation", true, "runtime"),
|
||||||
|
new RemappedConfigurationEntry("modRuntime", "runtimeOnly", false, ""),
|
||||||
|
new RemappedConfigurationEntry("modCompileOnly", "compileOnly", true, "")
|
||||||
|
);
|
||||||
|
|
||||||
public static final String INCLUDE = "include";
|
public static final String INCLUDE = "include";
|
||||||
public static final String MINECRAFT = "minecraft";
|
public static final String MINECRAFT = "minecraft";
|
||||||
|
@ -51,4 +55,6 @@ public class Constants {
|
||||||
public static final String MINECRAFT_LINEMAPPED = "minecraftLinemapped";
|
public static final String MINECRAFT_LINEMAPPED = "minecraftLinemapped";
|
||||||
public static final String MAPPINGS = "mappings";
|
public static final String MAPPINGS = "mappings";
|
||||||
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
||||||
|
|
||||||
|
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.2.0.3";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue