Skip to content

Commit

Permalink
Add the tests that validates that this is working.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Jul 17, 2024
1 parent 3a578aa commit 4806294
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,72 @@ class ConfigurationTests extends BuilderBasedTestSpecification {
!run.file('build/publications/maven/module.json').text.contains("dependencies")
!run.file('build/publications/maven/pom-default.xml').text.contains("dependencies")
}

def "a mod that lazily adds something to a dependency collector still gets its configuration resolved"() {
given:
def project = create("userdev_with_delayed_config_works", {
it.plugin('maven-publish')
it.build("""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
dependencies {
implementation 'net.neoforged:neoforge:+'
}
public interface ExampleDependencies extends Dependencies {
DependencyCollector getExample();
}
public abstract class ExampleExtensions {
@Nested
public abstract ExampleDependencies getDependencies();
default void dependencies(Action<? super ExampleDependencies> action) {
action.execute(getDependencies());
}
}
project.getExtensions().create("example", ExampleExtensions)
project.getConfigurations().create("exampleDependencies", conf -> {
conf.canBeResolved = true
conf.fromDependencyCollector(project.example.getDependencies().getExample())
});
example.dependencies {
example("junit:junit:4.12")
}
tasks.register("validateConfiguration", task -> {
task.doFirst({
project.getConfigurations().getByName("exampleDependencies").getResolvedConfiguration().getFirstLevelModuleDependencies().forEach(dep -> {
if (!dep.getModuleGroup().equals("junit")) {
throw new RuntimeException("Expected junit dependency, got " + dep.getModuleGroup())
}
})
if (project.getConfigurations().getByName("exampleDependencies").getResolvedConfiguration().getFirstLevelModuleDependencies().size() != 1) {
throw new RuntimeException("Expected 1 dependency, got " + project.getConfigurations().getByName("exampleDependencies").getResolvedConfiguration().getFirstLevelModuleDependencies().size())
}
})
})
""")
it.withToolchains()
it.withGlobalCacheDirectory(tempDir)
})

when:
def run = project.run {
it.tasks('validateConfiguration')
it.stacktrace()
}

then:
run.task(':validateConfiguration').outcome == TaskOutcome.SUCCESS
}
}

0 comments on commit 4806294

Please sign in to comment.