Skip to content

Commit

Permalink
MModdingGradle#configureFabricModJson can now be called multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Jun 2, 2024
1 parent ce1e1fd commit 8039a4d
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/main/java/com/mmodding/gradle/MModdingGradle.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@ public MModdingGradle(final ObjectFactory objects, final Project project) {
}

public void configureFabricModJson(Action<FabricModJson> action) {
var fmj = new FabricModJson();
fmj.fillDefaults(this.project);
action.execute(fmj);
if (this.project.getTasks().findByPath("generation/generateFmj") != null) {
var fmj = new FabricModJson();
fmj.fillDefaults(this.project);
action.execute(fmj);

GenerateFabricModJson task = this.project.getTasks().create("generateFmj", GenerateFabricModJson.class);
task.getModJson().set(fmj);
this.project.getTasks().getByPath("ideaSyncTask").dependsOn(task);
GenerateFabricModJson task = this.project.getTasks().create("generateFmj", GenerateFabricModJson.class);
task.getModJson().set(fmj);
this.project.getTasks().getByPath("ideaSyncTask").dependsOn(task);

JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
SourceSet mainSourceSet = javaExtension.getSourceSets().getByName("main");
mainSourceSet.getResources().srcDir(task);
JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
SourceSet mainSourceSet = javaExtension.getSourceSets().getByName("main");
mainSourceSet.getResources().srcDir(task);
}
else {
// Behaving differently if the FabricModJson already exists
GenerateFabricModJson task = (GenerateFabricModJson) this.project.getTasks().getByPath("generation/generateFmj");
FabricModJson fmj = task.getModJson().get();
action.execute(fmj);
task.getModJson().set(fmj);
}
}

public Dependency configureFMJForDependency(Dependency dependency, Action<FabricModJson> action) {
Expand Down

0 comments on commit 8039a4d

Please sign in to comment.