diff --git a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java index 7e4040d2b..53a52d426 100644 --- a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java +++ b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java @@ -10,6 +10,7 @@ import net.neoforged.gradle.common.runs.run.RunImpl; import net.neoforged.gradle.common.runs.tasks.RunsReport; import net.neoforged.gradle.common.runtime.definition.CommonRuntimeDefinition; +import net.neoforged.gradle.common.runtime.extensions.DefaultRuntimesContainer; import net.neoforged.gradle.common.runtime.extensions.RuntimesExtension; import net.neoforged.gradle.common.runtime.naming.OfficialNamingChannelConfigurator; import net.neoforged.gradle.common.tasks.CleanCache; @@ -35,6 +36,7 @@ import net.neoforged.gradle.dsl.common.runs.run.Run; import net.neoforged.gradle.dsl.common.runs.run.RunDevLogin; import net.neoforged.gradle.dsl.common.runs.type.RunType; +import net.neoforged.gradle.dsl.common.runtime.extensions.RuntimesContainer; import net.neoforged.gradle.dsl.common.util.ConfigurationUtils; import net.neoforged.gradle.dsl.common.util.NamingConstants; import net.neoforged.gradle.util.UrlConstants; @@ -70,8 +72,6 @@ public class CommonProjectPlugin implements Plugin { @Override public void apply(Project project) { - project.getObjects(). - //Apply the evaluation extension to monitor immediate execution of indirect tasks when evaluation already happened. project.getExtensions().create(NamingConstants.Extension.EVALUATION, ProjectEvaluationExtension.class, project); @@ -92,6 +92,7 @@ public void apply(Project project) { final ExtensionManager extensionManager = project.getExtensions().getByType(ExtensionManager.class); extensionManager.registerExtension("subsystems", Subsystems.class, (p) -> p.getObjects().newInstance(SubsystemsExtension.class, p)); + extensionManager.registerExtension("runtimes", RuntimesContainer.class, (p) -> p.getObjects().newInstance(DefaultRuntimesContainer.class, p)); project.getExtensions().create(IdeManagementExtension.class, "ideManager", IdeManagementExtension.class, project); project.getExtensions().create("allRuntimes", RuntimesExtension.class); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/AccessTransformersExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/AccessTransformersExtension.java index d7198e10d..1caee4c53 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/AccessTransformersExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/AccessTransformersExtension.java @@ -24,7 +24,7 @@ public AccessTransformersExtension(Project project) { this.projectDependencies = project.getDependencies(); this.projectArtifacts = project.getArtifacts(); - // We have to add these after project evaluation because of dependency replacement making configurations non-lazy; adding them earlier would prevent further addition of dependencies + // We have to add these after project evaluation because of dependency replacement making configurations non-lazy; adding them earlier would prevent further addition of compileDependencies project.afterEvaluate(p -> { p.getConfigurations().maybeCreate(CommonProjectPlugin.ACCESS_TRANSFORMER_CONFIGURATION).fromDependencyCollector(getConsume()); p.getConfigurations().maybeCreate(CommonProjectPlugin.ACCESS_TRANSFORMER_API_CONFIGURATION).fromDependencyCollector(getConsumeApi()); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/DefaultJarJarFeature.java b/common/src/main/java/net/neoforged/gradle/common/extensions/DefaultJarJarFeature.java index 75a9a4231..5a36b3c50 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/DefaultJarJarFeature.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/DefaultJarJarFeature.java @@ -130,7 +130,7 @@ public void createTaskAndConfiguration() { // Unfortunately, while we can hopefully rely on disambiguation rules to get us some of these, others run // into issues. The target JVM version is the most worrying - we don't want to pull in a variant for a newer // jvm version. We could copy DefaultJvmFeature, and search for the target version of the compile task, - // but this is difficult - we only have a feature name, not the linked source set. For this reason, we use + // but this is difficult - we only have a feature identifier, not the linked source set. For this reason, we use // the toolchain version, which is the most likely to be correct. attributes.attributeProvider(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, javaPlugin.getToolchain().getLanguageVersion().map(JavaLanguageVersion::asInt)); attributes.attribute(Usage.USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME)); @@ -141,7 +141,7 @@ public void createTaskAndConfiguration() { TaskProvider jarJarTask = project.getTasks().register(withPrefix(JAR_JAR_TASK_NAME), net.neoforged.gradle.common.tasks.JarJar.class, jarJar -> { jarJar.setGroup(JAR_JAR_GROUP); - jarJar.setDescription("Create a combined JAR of project and selected dependencies"); + jarJar.setDescription("Create a combined JAR of project and selected compileDependencies"); jarJar.getArchiveClassifier().convention(prefix.isEmpty() ? "all" : prefix + "-all"); if (!this.getDefaultSourcesDisabled()) { diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/ExtensionManager.java b/common/src/main/java/net/neoforged/gradle/common/extensions/ExtensionManager.java index 4779bbbe4..f5b97efe0 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/ExtensionManager.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/ExtensionManager.java @@ -73,7 +73,7 @@ public void registerExtension(String name, Class publicFacingType, IExten } } - throw new IllegalArgumentException("Property '" + String.format(EXTENSION_CHECK_PROPERTY_NAME, name) + "' is not a valid extension creator. It must be either a string of a class name implementing IExtensionCreator, or an instance of IExtensionCreator."); + throw new IllegalArgumentException("Property '" + String.format(EXTENSION_CHECK_PROPERTY_NAME, name) + "' is not a valid extension creator. It must be either a string of a class identifier implementing IExtensionCreator, or an instance of IExtensionCreator."); } public static void registerOverride(final Project project, final String name, final IExtensionCreator creator) { diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java index 6699fc2ad..9cd55fb4e 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java @@ -5,6 +5,7 @@ import com.google.gson.JsonObject; import net.minecraftforge.gdi.ConfigurableDSLElement; import net.neoforged.gradle.common.tasks.MinecraftArtifactFileCacheProvider; +import net.neoforged.gradle.common.tasks.MinecraftGameArtifactProvidingTask; import net.neoforged.gradle.common.tasks.MinecraftVersionManifestFileCacheProvider; import net.neoforged.gradle.common.util.FileCacheUtils; import net.neoforged.gradle.common.util.FileDownloadingUtils; @@ -31,6 +32,7 @@ import java.util.EnumMap; import java.util.Map; import java.util.Objects; +import java.util.SortedSet; import java.util.concurrent.ConcurrentHashMap; public abstract class MinecraftArtifactCacheExtension implements ConfigurableDSLElement, MinecraftArtifactCache { @@ -127,20 +129,18 @@ public final Map> cacheGameVers @NotNull @Override - public NamedDomainObjectProvider gameArtifactTask(@NotNull NamedDomainObjectCollection tasks, @NotNull GameArtifact artifact, @NotNull final String minecraftVersion) { - final MinecraftVersionAndUrl resolvedVersion = resolveVersion(minecraftVersion); - - if (artifact == GameArtifact.VERSION_MANIFEST) { - return tasks.named(NamingConstants.Task.CACHE_VERSION_MANIFEST + resolvedVersion.getVersion(), MinecraftVersionManifestFileCacheProvider.class); + public NamedDomainObjectProvider gameArtifactTask(@NotNull NamedDomainObjectCollection tasks, @NotNull GameArtifact artifact) { + final NamedDomainObjectCollection matchingTasks = tasks.withType(MinecraftGameArtifactProvidingTask.class) + .matching(task -> task.gameArtifact().equals(artifact)); + + final SortedSet matchingTaskNames = matchingTasks.getNames(); + if (matchingTaskNames.size() == 1) { + return matchingTasks.named(matchingTaskNames.first()); + } else if (matchingTaskNames.size() > 1) { + throw new IllegalStateException("Found multiple tasks for game artifact: " + artifact); + } else { + throw new IllegalStateException("Could not find task for game artifact: " + artifact); } - - final String taskName = "%s%s%s%s".formatted( - NamingConstants.Task.CACHE_VERSION_PREFIX, - StringUtils.capitalize(artifact.getType().orElseThrow().name().toLowerCase()), - StringUtils.capitalize(artifact.getDistributionType().orElseThrow().getName().toLowerCase()), - resolvedVersion.getVersion()); - - return tasks.named(taskName, MinecraftArtifactFileCacheProvider.class); } @Override diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/dependency/replacement/ReplacementLogic.java b/common/src/main/java/net/neoforged/gradle/common/extensions/dependency/replacement/ReplacementLogic.java index 910f73158..5b66ab549 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/dependency/replacement/ReplacementLogic.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/dependency/replacement/ReplacementLogic.java @@ -59,7 +59,7 @@ public ReplacementLogic(Project project) { @Override public void handleConfiguration(Configuration configuration) { //TODO: Figure out if there is any way to do this lazily. - //TODO: Configure each runs in an immutable context, so we can't add a listener to the dependencies. + //TODO: Configure each runs in an immutable context, so we can't add a listener to the compileDependencies. configuration.getDependencies().whenObjectAdded(dependency -> { //We need to check if our configuration is unhandled, we can only do this here and not in the register because of way we register unhandled configurations after their creation: //TODO: Find a better way to handle this. @@ -68,7 +68,7 @@ public void handleConfiguration(Configuration configuration) { return; } - //We only support module based dependencies. + //We only support module based compileDependencies. if (dependency instanceof ModuleDependency) { final ModuleDependency moduleDependency = (ModuleDependency) dependency; //Try replacing the dependency. @@ -232,7 +232,7 @@ void handleDependencyReplacement(Configuration configuration, Dependency depende } } - //For each configuration that we target we now need to add the new dependencies to. + //For each configuration that we target we now need to add the new compileDependencies to. for (Configuration targetConfiguration : targetConfigurations) { //Create a dependency from the tasks that copies the raw jar to the repository. //The sources jar is not needed here. @@ -254,7 +254,7 @@ void handleDependencyReplacement(Configuration configuration, Dependency depende * * @param dependency The dependency that is being replaced. * @param result The replacement result from one of the handlers. - * @param sourceArtifactSelectorName The name of the task that selects the source artifact. + * @param sourceArtifactSelectorName The identifier of the task that selects the source artifact. * @param newRepoEntry The new repository entry that the dependency is being replaced with. * @return The task that selects the source artifact from the dependency and puts it in the Ivy repository. */ @@ -268,7 +268,7 @@ private TaskProvider createOrLookupSourcesTask(Dependency //Create a new task, using the repository to create the output. final Repository repository = project.getExtensions().getByType(Repository.class); return project.getTasks().register(sourceArtifactSelectorName, ArtifactFromOutput.class, artifactFromOutput -> { - artifactFromOutput.setGroup("neogradle/dependencies"); + artifactFromOutput.setGroup("neogradle/compileDependencies"); artifactFromOutput.setDescription(String.format("Selects the source artifact from the %s dependency and puts it in the Ivy repository", dependency)); artifactFromOutput.getInput().set(result.getSourcesJar().flatMap(WithOutput::getOutput)); @@ -282,7 +282,7 @@ private TaskProvider createOrLookupSourcesTask(Dependency * * @param dependency The dependency that is being replaced. * @param result The replacement result from one of the handlers. - * @param rawArtifactSelectorName The name of the task that selects the raw artifact. + * @param rawArtifactSelectorName The identifier of the task that selects the raw artifact. * @param newRepoEntry The new repository entry that the dependency is being replaced with. * @return The task that selects the raw artifact from the dependency and puts it in the Ivy repository. */ @@ -296,7 +296,7 @@ private TaskProvider createOrLookupRawTask(Dependency depe // Create a new task, using the repository to create the output. final Repository repository = project.getExtensions().getByType(Repository.class); return project.getTasks().register(rawArtifactSelectorName, ArtifactFromOutput.class, artifactFromOutput -> { - artifactFromOutput.setGroup("neogradle/dependencies"); + artifactFromOutput.setGroup("neogradle/compileDependencies"); artifactFromOutput.setDescription(String.format("Selects the raw artifact from the %s dependency and puts it in the Ivy repository", dependency)); artifactFromOutput.getInput().set(result.getRawJar().flatMap(WithOutput::getOutput)); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyModuleWriter.java b/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyModuleWriter.java index ca3cbe8c5..0bbf52c3e 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyModuleWriter.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyModuleWriter.java @@ -92,7 +92,7 @@ private void writeInfo(final Dependency entry) throws XMLStreamException { // License // TODO: deal with custom projects? this.writer.writeEmptyElement("license"); - this.writer.writeAttribute("name", "Minecraft EULA"); + this.writer.writeAttribute("identifier", "Minecraft EULA"); this.writer.writeAttribute("url", "https://www.minecraft.net/en-us/eula"); // End @@ -100,7 +100,7 @@ private void writeInfo(final Dependency entry) throws XMLStreamException { } private void writeDependencies(final Configuration dependencies) throws XMLStreamException { - this.writer.writeStartElement("dependencies"); + this.writer.writeStartElement("compileDependencies"); for (final ResolvedArtifact extra : dependencies.getResolvedConfiguration().getResolvedArtifacts()) { this.writeDependency(extra); @@ -120,13 +120,13 @@ private void writeDependency(final ResolvedArtifact dep) throws XMLStreamExcepti } this.writer.writeAttribute("org", dep.getModuleVersion().getId().getGroup()); - this.writer.writeAttribute("name", dep.getModuleVersion().getId().getName()); + this.writer.writeAttribute("identifier", dep.getModuleVersion().getId().getName()); this.writer.writeAttribute("rev", dep.getModuleVersion().getId().getVersion()); this.writer.writeAttribute("transitive", "false"); if (hasClassifier) { this.writer.writeEmptyElement("artifact"); - this.writer.writeAttribute("name", dep.getModuleVersion().getId().getName()); + this.writer.writeAttribute("identifier", dep.getModuleVersion().getId().getName()); this.writer.writeAttribute("classifier", classifier); this.writer.writeAttribute("ext", "jar"); this.writer.writeEndElement(); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyRepository.java b/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyRepository.java index 5783a1507..11c48e718 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyRepository.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/repository/IvyRepository.java @@ -190,7 +190,7 @@ private void writeDummyDataIfNeeded( final Configuration dependencies, final boolean hasSource ) throws IOException, XMLStreamException { - //Construct all paths, ensuring that the metadata file name matches the pattern we configured above in the repo metadata. + //Construct all paths, ensuring that the metadata file identifier matches the pattern we configured above in the repo metadata. final Path jarFile = buildArtifactPath(entry); final Path baseDir = jarFile.getParent(); final Path metaFile = baseDir.resolve(String.format("ivy-%s-ng%d.xml", entry.getVersion(), METADATA_VERSION)); diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java index 2a2f99744..a62b5abab 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java @@ -110,7 +110,7 @@ public void configureIdeaConventions(Project project, IDEA ideaConventions) { final File DotIdeaDirectory = new File(project.getProjectDir(), ".idea"); final File GradleXml = new File(DotIdeaDirectory, "gradle.xml"); - return FileUtils.contains(GradleXml, "