-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement support for dynamic runtime dependencies #52
Conversation
Thank you for working on this! Had a quick test, and hit a couple of issues: Duplicate
|
Applying following patch fixed the two issues, but not sure if it's the best fix: 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 943458c5..a9157569 100644
--- a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java
+++ b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java
@@ -136,14 +136,12 @@ public class CommonProjectPlugin implements Plugin<Project> {
if (run.getConfigureFromDependencies().get()) {
final RunImpl runImpl = (RunImpl) run;
- runImpl.getModSources().get().forEach(sourceSet -> {
- try {
- final Optional<CommonRuntimeDefinition<?>> definition = TaskDependencyUtils.findRuntimeDefinition(project, sourceSet);
- definition.ifPresent(def -> def.configureRun(runImpl));
- } catch (MultipleDefinitionsFoundException e) {
- throw new RuntimeException("Failed to configure run: " + run.getName() + " there are multiple runtime definitions found for the source set: " + sourceSet.getName(), e);
- }
- });
+ try {
+ final Optional<CommonRuntimeDefinition<?>> definition = TaskDependencyUtils.findRuntimeDefinition(project, runImpl.getModSources().get());
+ definition.ifPresent(def -> def.configureRun(runImpl));
+ } catch (MultipleDefinitionsFoundException e) {
+ throw new RuntimeException("Failed to configure run " + run.getName() + ": multiple runtime definitions were found.", e);
+ }
}
}
}));
diff --git a/common/src/main/java/net/neoforged/gradle/common/util/TaskDependencyUtils.java b/common/src/main/java/net/neoforged/gradle/common/util/TaskDependencyUtils.java
index baeeba54..89aacc0c 100644
--- a/common/src/main/java/net/neoforged/gradle/common/util/TaskDependencyUtils.java
+++ b/common/src/main/java/net/neoforged/gradle/common/util/TaskDependencyUtils.java
@@ -91,8 +91,8 @@ public final class TaskDependencyUtils {
public static CommonRuntimeDefinition<?> extractRuntimeDefinition(Project project, Collection<SourceSet> sourceSets) throws MultipleDefinitionsFoundException, NoDefinitionsFoundException {
return validateAndUnwrapDefinitions(project, "source sets", sourceSets.stream().map(SourceSet::getName).collect(Collectors.joining(", ", "[", "]")), findRuntimes(project, sourceSets));
}
-
- public static Optional<CommonRuntimeDefinition<?>> findRuntimeDefinition(Project project, SourceSet sourceSet) throws MultipleDefinitionsFoundException {
+
+ public static Optional<CommonRuntimeDefinition<?>> findRuntimeDefinition(Project project, Collection<SourceSet> sourceSet) throws MultipleDefinitionsFoundException {
return unwrapDefinitions(project, findRuntimes(project, sourceSet));
}
diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/run/RunDependency.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/run/RunDependency.groovy
index b5be7d84..a771eb0a 100644
--- a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/run/RunDependency.groovy
+++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/run/RunDependency.groovy
@@ -1,7 +1,7 @@
package net.neoforged.gradle.dsl.common.runs.run
import groovy.transform.CompileStatic
-import net.minecraftforge.gdi.BaseDSLElement
+import net.minecraftforge.gdi.ConfigurableDSLElement
import net.minecraftforge.gdi.annotations.DSLProperty
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.provider.Property
@@ -11,7 +11,7 @@ import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
@CompileStatic
-interface RunDependency extends BaseDSLElement<RunDependency> {
+interface RunDependency extends ConfigurableDSLElement<RunDependency> {
@InputFiles
@PathSensitive(PathSensitivity.NONE) |
@SquidDev Can you check if it is fixed with the commit I just pushed? |
1 similar comment
@SquidDev Can you check if it is fixed with the commit I just pushed? |
Yep, that also works, thank you! Is there any reason |
There are weird circumstances where if you do: something {
blah project.something.or.another
} It can fail to find the project, because of the way the configuration mechanic works with closures. In practice everything exposed in the DSL needs to be a |
I am going to add feedback here, but if there is a better place for it I will move it. I have tried to add an external library as described here on NF
Have I misconfigured it? I have followed the steps provided in this PR. |
Please contact support on our discord |
Run specific dependency management
This implements run specific dependency management for the classpath of a run.
In the past this had to happen via a manual modification of the "minecraft_classpath" token, however tokens don't exist anymore as a component that can be configured on a run.
It was as such not possible to add none FML aware libraries to your classpath of a run.
This PR enables this feature again.
Usage:
Direct
Configuration
General description
The dependency handler on a run works very similar to a projects own dependency handler, however it has only one "configuration" available to add dependencies to: "runtime". Additionally it provides a method to use when you want to turn an entire configuration into a runtime dependency.
PR Details
Requirements:
As in F/NG6 you still need to add the library dependency either to the compile or runtime classpath of the sourceset that you use as a mod sourceset.
Beyond that you will now need to tell each run that needs it, what dependency it should load.
API Changes
Implementation changes: