Skip to content

Commit 75bf303

Browse files
authored
Improve the handling of the IDEA extension. (#272)
1 parent 9422af6 commit 75bf303

7 files changed

Lines changed: 106 additions & 20 deletions

File tree

README.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,6 @@ using [Gradle properties](https://docs.gradle.org/current/userguide/project_prop
514514
This implements run specific dependency management for the classpath of a run.
515515
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.
516516
It was as such not possible to add none FML aware libraries to your classpath of a run.
517-
This PR enables this feature again.
518-
519517

520518
### Usage:
521519
#### Direct
@@ -699,27 +697,73 @@ If you have configured your IDEA IDE to run with its own compiler, you can disab
699697
```properties
700698
neogradle.subsystems.conventions.ide.idea.compiler-detection=false
701699
```
702-
This will set the DSL property:
700+
This auto-detection will set the DSL property, disabling this property while running and compiling with idea means that you need to set this property yourself.
703701
```groovy
704702
idea {
705-
runs {
703+
project {
704+
runs {
705+
runWithIdea = true / false
706+
}
707+
}
708+
}
709+
```
710+
711+
> [!NOTE]
712+
> This API is only available on the root project, since that is where the idea project model resides.
713+
714+
If for what ever reason IDEA does not properly register its model in your root project you can also use:
715+
```groovy
716+
minecraft {
717+
idea {
706718
runWithIdea = true / false
707719
}
708720
}
709721
```
710-
##### IDEA Compiler output directory
711-
If you want to change the output directory of the IDEA compiler, you can set the following property in your gradle.properties:
722+
723+
> [!WARNING]
724+
> This model is project specific, as apposed to the API shown above which is only available on the root project.
725+
> It should as such be set on all projects at once. We suggest using a convention plugin or a similar Config Cache compatible mechanism.
726+
727+
##### Using Arg Files
728+
Sometimes IDEA will generate a Config Cache incompatible init script when its command line arguments are shortened using an args file and running with Gradle is enabled (which is the default).
729+
To prevent gradle from being mad at idea for the incompatible script you can make NG generate a launch configuration that does not shorten the command line.
730+
731+
> [!NOTE]
732+
> This might not work on all operating systems. Some configurations of paths might prevent you from launching the game because the launch command got too long.
733+
734+
You can either use the following convention:
712735
```properties
713-
neogradle.subsystems.conventions.ide.idea.compiler-output-dir=<path>
736+
neogradle.subsystems.conventions.ide.idea.use-args-file=false
714737
```
715-
By default, this is set to 'out', and configured in the DSL as:
738+
739+
Or the following model APIs:
740+
716741
```groovy
717742
idea {
718-
runs {
719-
outDirectory = '<path>'
743+
project {
744+
runs {
745+
useArgsFile = true / false
746+
}
720747
}
721748
}
722749
```
750+
Will configure the system to use your preferred convention.
751+
752+
> [!NOTE]
753+
> This API is only available on the root project, since that is where the idea project model resides.
754+
755+
If for what ever reason IDEA does not properly register its model in your root project you can also use:
756+
```groovy
757+
minecraft {
758+
idea {
759+
useArgsFile = true / false
760+
}
761+
}
762+
```
763+
764+
> [!WARNING]
765+
> This model is project specific, as apposed to the API shown above which is only available on the root project.
766+
> It should as such be set on all projects at once. We suggest using a convention plugin or a similar Config Cache compatible mechanism.
723767
724768
##### Post Sync Task Usage
725769
By default, the import in IDEA is run during the sync task.

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ subprojects.forEach { Project subProject ->
5151
subProject.apply plugin: 'eclipse'
5252
subProject.apply plugin: 'idea'
5353

54-
gradleutils.setupSigning(project: subProject, signAllPublications: true)
54+
//TODO: Figure out why eclipse project signing is fucked with GU
55+
if (subProject.name != "eclipse")
56+
gradleutils.setupSigning(project: subProject, signAllPublications: true)
5557

5658
//General project metadata. Everything has the same version and group.
5759
subProject.version = subProject.rootProject.version

common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public IDEAExtension(WithEnabledProperty parent) {
149149
getShouldUseCompilerDetection().convention(getBooleanProperty("compiler-detection", true, false));
150150
getShouldUsePostSyncTask().convention(getBooleanProperty("use-post-sync-task", false, false));
151151
getShouldReconfigureTemplatesForTests().convention(getBooleanProperty("reconfigure-unit-test-templates", false, false));
152+
getShouldUseArgsFile().convention(getBooleanProperty("use-args-file", true, true));
152153
}
153154
}
154155
}

common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.neoforged.gradle.common.util.ProjectUtils;
1313
import net.neoforged.gradle.common.util.SourceSetUtils;
1414
import net.neoforged.gradle.common.util.run.RunsUtil;
15+
import net.neoforged.gradle.dsl.common.extensions.Minecraft;
1516
import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems;
1617
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.ide.IDEA;
1718
import net.neoforged.gradle.dsl.common.runs.ide.extensions.IdeaRunExtension;
@@ -83,8 +84,25 @@ public void setup(final Project project) {
8384
final IdeaModel ideaModel = rootProject.getExtensions().getByType(IdeaModel.class);
8485
final IdeaProject ideaProject = ideaModel.getProject();
8586
final ExtensionAware extensionAware = (ExtensionAware) ideaProject;
87+
final IdeaRunsExtension global;
8688
if (extensionAware.getExtensions().findByType(IdeaRunsExtension.class) == null && extensionAware.getExtensions().findByName("runs") == null) {
87-
extensionAware.getExtensions().create("runs", IdeaRunsExtension.class, project);
89+
global = extensionAware.getExtensions().create("runs", IdeaRunsExtension.class, project);
90+
}
91+
else if (extensionAware.getExtensions().findByType(IdeaRunsExtension.class) != null)
92+
{
93+
global = extensionAware.getExtensions().findByType(IdeaRunsExtension.class);
94+
}
95+
else
96+
{
97+
project.getLogger().warn("Runs extension for idea can not be registered on the Idea project model. Use the one in the minecraft extension.");
98+
global = null;
99+
}
100+
101+
final Minecraft minecraft = project.getExtensions().getByType(Minecraft.class);
102+
final IdeaRunsExtension projectLocal = minecraft.getExtensions().create("idea", IdeaRunsExtension.class, project);
103+
if (global != null) {
104+
projectLocal.getUseArgsFile().convention(global.getUseArgsFile());
105+
projectLocal.getRunWithIdea().convention(global.getRunWithIdea());
88106
}
89107
}
90108

@@ -123,6 +141,8 @@ public void configureIdeaConventions(Project project, IDEA ideaConventions) {
123141
return FileUtils.contains(GradleXml, "<option name=\"delegatedBuild\" value=\"false\" />");
124142
})
125143
);
144+
145+
runsExtension.getUseArgsFile().convention(ideaConventions.getShouldUseArgsFile());
126146
}
127147

128148
private static final class RunsImportAction implements IdeManagementExtension.IdeImportAction {
@@ -175,6 +195,9 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
175195
if (!defaultRun && !run.getShouldExportToIDE().get())
176196
return;
177197

198+
final Minecraft minecraft = project.getExtensions().getByType(Minecraft.class);
199+
final IdeaRunsExtension ideaRunsExtension = minecraft.getExtensions().getByType(IdeaRunsExtension.class);
200+
178201
final String ideRunName = run.getIDERunName().isPresent() ? run.getIDERunName().get() : run.getName();
179202
final String runName = StringUtils.capitalize(project.getName() + ": " + StringUtils.capitalize(ideRunName));
180203

@@ -208,7 +231,9 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
208231
ideaRun.setModuleName(RunsUtil.getIntellijModuleName(run.getExtensions().getByType(IdeaRunExtension.class).getPrimarySourceSet().get()));
209232
ideaRun.setProgramParameters(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(programArguments.stream()).collect(Collectors.toList())));
210233
ideaRun.setEnvs(productionEnvironment);
211-
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);
234+
235+
if (ideaRunsExtension.getUseArgsFile().get())
236+
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);
212237

213238
ideaRun.beforeRun(beforeRuns -> {
214239
beforeRuns.create("Build", Make.class);
@@ -240,7 +265,9 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
240265
"@%s".formatted(preparedUnitTestEnvironment.jvmArgumentsFile().getAbsolutePath())
241266
));
242267
ideaRun.setEnvs(testEnvironment);
243-
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);
268+
269+
if (ideaRunsExtension.getUseArgsFile().get())
270+
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);
244271

245272
ideaRun.beforeRun(beforeRuns -> {
246273
beforeRuns.create("Build", Make.class);

dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/extensions/subsystems/conventions/ide/IDEA.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ interface IDEA extends BaseDSLElement<IDEA> {
3333
*/
3434
@DSLProperty
3535
Property<Boolean> getShouldReconfigureTemplatesForTests();
36+
37+
/**
38+
* Whether or not IDEA should run with args files.
39+
*/
40+
@DSLProperty
41+
Property<Boolean> getShouldUseArgsFile()
3642
}

dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/runs/idea/extensions/IdeaRunsExtension.groovy

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ abstract class IdeaRunsExtension implements BaseDSLElement<IdeaRunsExtension> {
1414

1515
private final Project project;
1616
private final Property<Boolean> runWithIdea;
17-
private final DirectoryProperty outDirectory;
17+
private final Property<Boolean> useArgsFile;
1818

1919
@Inject
2020
IdeaRunsExtension(final Project project) {
21-
this.project = project;
21+
this.project = project
2222

23-
this.runWithIdea = project.getObjects().property(Boolean);
24-
this.outDirectory = project.getObjects().directoryProperty();
23+
this.runWithIdea = project.getObjects().property(Boolean)
24+
this.useArgsFile = project.getObjects().property(Boolean)
2525

26-
getRunWithIdea().convention(false);
26+
getRunWithIdea().convention(false)
27+
getUseArgsFile().convention(true)
2728
}
2829

2930
@Override
@@ -35,4 +36,9 @@ abstract class IdeaRunsExtension implements BaseDSLElement<IdeaRunsExtension> {
3536
Property<Boolean> getRunWithIdea() {
3637
return runWithIdea;
3738
}
39+
40+
@DSLProperty
41+
Property<Boolean> getUseArgsFile() {
42+
return useArgsFile;
43+
}
3844
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ diffpatch_version=2.0.0.35
2626
jarjar_version=0.4.1
2727
jetbrains_annotations_version=23.0.0
2828
gradle_idea_extension_version=1.1.6
29-
groovy_dsl_improver_version=1.0.16
29+
groovy_dsl_improver_version=1.0.18
3030
eclipse_launch_configs_version=0.1.3
3131
vscode_launch_configs_version=1.0.8
3232

0 commit comments

Comments
 (0)