diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy index 49feae12..d19692db 100644 --- a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy +++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/type/RunType.groovy @@ -100,6 +100,12 @@ abstract class RunType implements ConfigurableDSLElement, NamedDSLEleme other.getEnvironmentVariables().set(getEnvironmentVariables()) other.getSystemProperties().set(getSystemProperties()) other.getClasspath().from(getClasspath()) + + if (runTemplate != null && other.getRunTemplate() != null) { + other.getRunTemplate().configure(runTemplate) + } else if (runTemplate == null) { + other.setRunTemplate(null) + } } /** 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 f32b81cf..0cfd947f 100644 --- a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy @@ -552,4 +552,69 @@ class RunTests extends BuilderBasedTestSpecification { secondSection == thirdSection thirdSection == firstSection } + + def "runs use a working directory named after them by default"() { + given: + def project = create("runs_have_configurable_working_directories_with_default", { + it.property('neogradle.subsystems.conventions.runs.enabled', 'false') + it.build(""" + java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } + } + + repositories { + mavenCentral() + } + + dependencies { + implementation 'net.neoforged:neoforge:+' + } + + runs { + aClient { + runType 'client' + } + + bClient { + runType 'client' + } + + cClient { + runType 'client' + + workingDirectory project.file("clientThree") + } + } + + """) + it.withToolchains() + it.withGlobalCacheDirectory(tempDir) + }) + + when: + def run = project.run { + it.tasks(':runs') + it.stacktrace() + } + + then: + def lines = run.getOutput().split("\n"); + def firstRunIndex = lines.findIndexOf { line -> line.startsWith("Run: aClient")} + def secondRunIndex = lines.findIndexOf { line -> line.startsWith("Run: bClient")} + def thirdRunIndex = lines.findIndexOf { line -> line.startsWith("Run: cClient")} + def endIndex = lines.findIndexOf { line -> line.startsWith("BUILD SUCCESSFUL")} + + def indexes = [firstRunIndex + 1, secondRunIndex + 1, thirdRunIndex + 1, endIndex] + indexes.sort() + + def firstSection = lines[indexes[0]..indexes[1] - 2] + def secondSection = lines[indexes[1]..indexes[2] - 2] + def thirdSection = lines[indexes[2]..indexes[3] - 2] + + firstSection.find { it.contains("Working Directory:") }.toString().split(":")[1].trim().endsWith("runs_have_configurable_working_directories_with_default/runs/aClient") + secondSection.find { it.contains("Working Directory:") }.toString().split(":")[1].trim().endsWith("runs_have_configurable_working_directories_with_default/runs/bClient") + thirdSection.find { it.contains("Working Directory:") }.toString().split(":")[1].trim().endsWith("runs_have_configurable_working_directories_with_default/clientThree") + } }