@@ -118,41 +118,44 @@ public void configureTesting(SetProperty<ModModel> loadedMods,
118118 File gameDirectory ,
119119 Provider <RegularFile > programArgsFile ,
120120 Provider <RegularFile > vmArgsFile ) {
121- // Write out a separate file that has IDE specific VM args, which include the definition of the output directories.
122- // For JUnit we have to write this to a separate file due to the Run parameters being shared among all projects.
123- var intellijVmArgsFile = runArgsDir .map (dir -> dir .file ("intellijVmArgs.txt" ));
124-
125- var outputDirectory = IntelliJOutputDirectoryValueSource .getIntellijOutputDirectory (project );
126- var ideSpecificVmArgs = RunUtils .escapeJvmArg (getModFoldersProvider (project , outputDirectory , loadedMods , testedMod ).getArgument ());
127- try {
128- var vmArgsFilePath = intellijVmArgsFile .get ().getAsFile ().toPath ();
129- Files .createDirectories (vmArgsFilePath .getParent ());
130- // JVM args generally expect platform encoding
131- FileUtils .writeStringSafe (vmArgsFilePath , ideSpecificVmArgs , StringUtils .getNativeCharset ());
132- } catch (IOException e ) {
133- throw new GradleException ("Failed to write VM args file for IntelliJ unit tests" , e );
134- }
121+ // IDEA Sync has no real notion of tasks or providers or similar
122+ project .afterEvaluate (ignored -> {
123+ // Write out a separate file that has IDE specific VM args, which include the definition of the output directories.
124+ // For JUnit we have to write this to a separate file due to the Run parameters being shared among all projects.
125+ var intellijVmArgsFile = runArgsDir .map (dir -> dir .file ("intellijVmArgs.txt" ));
126+
127+ var outputDirectory = IntelliJOutputDirectoryValueSource .getIntellijOutputDirectory (project );
128+ var ideSpecificVmArgs = RunUtils .escapeJvmArg (getModFoldersProvider (project , outputDirectory , loadedMods , testedMod ).getArgument ());
129+ try {
130+ var vmArgsFilePath = intellijVmArgsFile .get ().getAsFile ().toPath ();
131+ Files .createDirectories (vmArgsFilePath .getParent ());
132+ // JVM args generally expect platform encoding
133+ FileUtils .writeStringSafe (vmArgsFilePath , ideSpecificVmArgs , StringUtils .getNativeCharset ());
134+ } catch (IOException e ) {
135+ throw new GradleException ("Failed to write VM args file for IntelliJ unit tests" , e );
136+ }
135137
136- // Configure IntelliJ default JUnit parameters, which are used when the user configures IJ to run tests natively
137- // IMPORTANT: This affects *all projects*, not just this one. We have to use $MODULE_WORKING_DIR$ to make it work.
138- var intelliJRunConfigurations = getIntelliJRunConfigurations ();
139- if (intelliJRunConfigurations != null ) {
140- intelliJRunConfigurations .defaults (JUnit .class , jUnitDefaults -> {
141- // $MODULE_WORKING_DIR$ is documented here: https://www.jetbrains.com/help/idea/absolute-path-variables.html
142- jUnitDefaults .setWorkingDirectory ("$MODULE_WORKING_DIR$/" + ModDevPlugin .JUNIT_GAME_DIR );
143- jUnitDefaults .setVmParameters (
144- // The FML JUnit plugin uses this system property to read a file containing the program arguments needed to launch
145- // NOTE: IntelliJ does not support $MODULE_WORKING_DIR$ in VM Arguments
146- // See https://youtrack.jetbrains.com/issue/IJPL-14230/Add-macro-support-for-VM-options-field-e.g.-expand-ModuleFileDir-properly
147- // As a workaround, we just use paths relative to the working directory.
148- RunUtils .escapeJvmArg ("-Dfml.junit.argsfile=" + buildRelativePath (programArgsFile , gameDirectory ))
149- + " "
150- + RunUtils .escapeJvmArg ("@" + buildRelativePath (vmArgsFile , gameDirectory ))
151- + " "
152- + RunUtils .escapeJvmArg ("@" + buildRelativePath (intellijVmArgsFile , gameDirectory ))
153- );
154- });
155- }
138+ // Configure IntelliJ default JUnit parameters, which are used when the user configures IJ to run tests natively
139+ // IMPORTANT: This affects *all projects*, not just this one. We have to use $MODULE_WORKING_DIR$ to make it work.
140+ var intelliJRunConfigurations = getIntelliJRunConfigurations ();
141+ if (intelliJRunConfigurations != null ) {
142+ intelliJRunConfigurations .defaults (JUnit .class , jUnitDefaults -> {
143+ // $MODULE_WORKING_DIR$ is documented here: https://www.jetbrains.com/help/idea/absolute-path-variables.html
144+ jUnitDefaults .setWorkingDirectory ("$MODULE_WORKING_DIR$/" + ModDevPlugin .JUNIT_GAME_DIR );
145+ jUnitDefaults .setVmParameters (
146+ // The FML JUnit plugin uses this system property to read a file containing the program arguments needed to launch
147+ // NOTE: IntelliJ does not support $MODULE_WORKING_DIR$ in VM Arguments
148+ // See https://youtrack.jetbrains.com/issue/IJPL-14230/Add-macro-support-for-VM-options-field-e.g.-expand-ModuleFileDir-properly
149+ // As a workaround, we just use paths relative to the working directory.
150+ RunUtils .escapeJvmArg ("-Dfml.junit.argsfile=" + buildRelativePath (programArgsFile , gameDirectory ))
151+ + " "
152+ + RunUtils .escapeJvmArg ("@" + buildRelativePath (vmArgsFile , gameDirectory ))
153+ + " "
154+ + RunUtils .escapeJvmArg ("@" + buildRelativePath (intellijVmArgsFile , gameDirectory ))
155+ );
156+ });
157+ }
158+ });
156159 }
157160
158161 @ Nullable
0 commit comments