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 f56ed054..2d14ce9d 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 @@ -48,10 +48,11 @@ public abstract class ReplacementLogic implements ConfigurableDSLElement this.project.getObjects().newInstance(Handler.class, this.project, name)); + + //Wire up a replacement handler to each configuration for when a dependency is added. + this.project.getConfigurations().configureEach(this::handleConfiguration); } @Override 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 979b3f7e..14e375cc 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 @@ -152,6 +152,11 @@ public void idea(Project project, Project rootProject, IdeaModel idea, ProjectSe final ExtensionAware ideaModelExtensions = (ExtensionAware) idea; final Run ideaDefaultUnitTestRun = ideaModelExtensions.getExtensions().getByType(Run.class); + //We finally know that the user wants this to be registered, additionally the IDE integration resolved the lazy dependencies + //here, so we can now with a gentle heart register the run type, and the run configuration conversion. + RunManager runManager = project.getExtensions().getByType(RunManager.class); + runManager.addInternal(ideaDefaultUnitTestRun); + createIdeaRun(project, ideaDefaultUnitTestRun, ideaRuns, true); } }); diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java index 77b95be2..ca91afff 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java @@ -263,7 +263,7 @@ public Provider> getSdkClasspathElements() { } @Override - public void runType(@NotNull String string) { + public void runType(@NotNull String name) { getConfigureFromTypeWithName().set(false); // Don't re-configure specifications.addAll(getRunTypesByName(name)); } diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/unittest/UnitTestConfigurator.java b/common/src/main/java/net/neoforged/gradle/common/runs/unittest/UnitTestConfigurator.java index 54d8b0f6..401359e2 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/unittest/UnitTestConfigurator.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/unittest/UnitTestConfigurator.java @@ -26,9 +26,6 @@ public static void configureIdeUnitTests(final Project project) { ideaDefaultTestRun.getIsJUnit().set(true); ideaDefaultTestRun.runType("junit"); - - RunManager runManager = project.getExtensions().getByType(RunManager.class); - runManager.addInternal(ideaDefaultTestRun); }); } } diff --git a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java index dc70fd2f..ed4465b6 100644 --- a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java +++ b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java @@ -64,7 +64,7 @@ public static String createTaskName(final String prefix, final Run run) { } public static void configure(Project project, Run run, boolean isInternal) { - RunsUtil.configureModSourceDefaults(project, run, isInternal); + RunsUtil.configureModSourceDefaults(project, run); run.configure(); @@ -131,12 +131,7 @@ public static void ensureMacOsSupport(Run run) { } } - public static void configureModSourceDefaults(Project project, Run run, boolean isInternal) { - if (isInternal) { - return; - } - - // We add default junit sourcesets here because we need to know the type of the run first + public static void configureModSourceDefaults(Project project, Run run) { final Conventions conventions = project.getExtensions().getByType(Subsystems.class).getConventions(); if (conventions.getSourceSets().getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) { //We always register main diff --git a/userdev/build.gradle b/userdev/build.gradle index 4f96ade6..580f256d 100644 --- a/userdev/build.gradle +++ b/userdev/build.gradle @@ -7,6 +7,4 @@ dependencies { api project(':common') api project(':neoform') api project(':dsl-userdev') -} - - +} \ No newline at end of file diff --git a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy index 94cbdb4e..2a3af8bf 100644 --- a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy @@ -373,6 +373,11 @@ class RunTests extends BuilderBasedTestSpecification { classpathFile.text.contains("org.jgrapht${File.separator}jgrapht-core") } + @Override + protected File getTestTempDirectory() { + return new File("build", "unit-testing-2") + } + def "userdev supports unit testing"() { given: def project = create("userdev_supports_unit_tests", { @@ -394,10 +399,22 @@ class RunTests extends BuilderBasedTestSpecification { } } + test { + useJUnitPlatform() + } + dependencies { implementation 'net.neoforged:neoforge:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' } """) + //We need to add a manifest.mf file to the test source set + it.file("src/test/resources/META-INF/MANIFEST.MF", """Manifest-Version: 1.0 + |FMLModType: GAMELIBRARY + |""".stripMargin()) + it.file("src/test/java/net/test/TestTest.java", """ package net.test; @@ -427,11 +444,11 @@ class RunTests extends BuilderBasedTestSpecification { when: def run = project.run { - it.tasks(':test') + it.tasks(":testJunit") } then: - run.task(':test').outcome == TaskOutcome.SUCCESS + run.task(':testJunit').outcome == TaskOutcome.SUCCESS } def "runs with no modsource create problem"() { diff --git a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/SourceSetConventionTests.groovy b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/SourceSetConventionTests.groovy index 8be8c56a..6068a45f 100644 --- a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/SourceSetConventionTests.groovy +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/convention/SourceSetConventionTests.groovy @@ -489,7 +489,7 @@ class SourceSetConventionTests extends BuilderBasedTestSpecification { } afterEvaluate { - logger.lifecycle("Run contains cp entry: \${project.runs.client.dependencies.get().runtimeConfiguration.files.any { it.name.contains 'jgrapht' }}") + logger.lifecycle("Run contains cp entry: \${project.runs.client.dependencies.runtimeConfiguration.files.any { it.name.contains 'jgrapht' }}") } """) it.withToolchains() @@ -530,7 +530,7 @@ class SourceSetConventionTests extends BuilderBasedTestSpecification { } afterEvaluate { - logger.lifecycle("Run contains cp entry: \${project.runs.client.dependencies.get().runtimeConfiguration.files.any { it.name.contains 'jgrapht' }}") + logger.lifecycle("Run contains cp entry: \${project.runs.client.dependencies.runtimeConfiguration.files.any { it.name.contains 'jgrapht' }}") } """) it.withToolchains()