When I run tests I get the error "Command line is too long". It works if I set the "Shorten command line" method in the Run/Debug configuration to "JAR manifest" for the specific method or class, but how do I set it for the whole project or is there an IDE global setting for it?
10 Answers
Inside your .idea folder, change workspace.xml file
Add
<property name="dynamic.classpath" value="true" />
to
<component name="PropertiesComponent">
.
.
.
</component>
Example
<component name="PropertiesComponent">
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.proportion" value="0.0" />
<property name="project.structure.side.proportion" value="0.0" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
<property name="dynamic.classpath" value="true" />
</component>
If you don't see one, feel free to add it yourself
<component name="PropertiesComponent">
<property name="dynamic.classpath" value="true" />
</component>
Community edit: this solution does not seem to work in newer versions of IDE, the format of PropertiesComponent
is different now. If that's your case, then this answer should work
-
5This method works in the event that your version of intellij doesn't have the GUI method of setting this. I'd like to point out, it may be the .idea/workspace.xml file OR
.iws file. If you don't have a .idea folder, search for an .iws file in your project. – Dennis Bartlett Feb 25 '19 at 17:14 -
1Thanks! It works for me in Android Studio 4.0 – DungPhan Dec 15 '20 at 02:47
-
1This didn't work for me, although obviously working for others so not sure why – Daniel Wilson Jul 21 '21 at 16:18
-
you can do this in
.iml file as well if you cant find .iws file or /.idea directory – Alok Mishra Dec 16 '21 at 12:56
Intellij 2018.2.5
Run => Edit Configurations => Choose Node on the left hand side => expand Environment => Shorten Command line options => choose Classpath file or JAR manifest

- 3,277
- 1
- 17
- 13
-
21This solution has to be set new every time you run a single test you haven't run before – 4ndro1d Jan 07 '19 at 12:34
-
5You can set this on the template for the configuration type you are setting up and it will not need to be set for every new test/configuration. See the accepted answer for details. – Dennis Bartlett Feb 25 '19 at 17:11
-
1
You can set up a default way to shorten the command line and use it as a template for further configurations by changing the default JUnit Run/Debug Configuration template. Then all new Run/Debug configuration you create in project will use the same option.
Here is the related blog post about configurable command line shortener option.

- 15,144
- 25
- 91
- 187
-
8It doesnt work anymore in the new version because the option got deleted. How to do it now? – Mulgard Apr 25 '18 at 13:16
-
56The setting that worked for me is to select option "classpath file" on the dialog that comes up from clicking the link the error message. This is under the setting "Shorten command line". – havoc1 Oct 04 '18 at 14:06
-
3select option "classpath file" works and I would suggest to include this option in the answer for newer version of IDE. – MrKumar Nov 14 '19 at 17:42
-
2@MrKumar i get: 'CommandLineWrapper' is ill-suited for launching apps on Java 9+. If the run configuration uses "classpath file", please change it to "@argfile". Otherwise, please contact support. – Tym Pollack Aug 20 '20 at 21:22
-
3Hey @TymPollack I got that too and fixed it by going to Run -> Edit Configurations. In the Shorten Command Line section, I chose user-local option and it worked. Try it see if it works. I am on AS 4.2 – Beast77 May 07 '21 at 12:58
-
3In IJ version 2021, the "Shorten command line" option is hidden by default. To see it, choose "Modify options" -> check "Shorten command line". – kabeen Jun 08 '21 at 08:22
The latest 2020 build doesn't have the shorten command line option by default we need to add that option from the configuration.
Run > Edit Configurations > Select the corresponding run configuration and click on Modify options for adding the shorten command-line configuration to the UI.
Select the shorten command line option
Now choose jar manifest from the shorten command line option

- 3,146
- 1
- 20
- 29
-
4I could not found nay solutions because all answer was a old version! This really help me! thanks a lot! – AntoCode Apr 08 '21 at 09:23
-
Thanks to Rajesh Goel in Android Studio
:
Run > Edit Configurations...
Select a test (better to select a parent test class) and set a Shorten command line:
option to classpath file
. Then OK (or Apply, OK).

- 26,736
- 15
- 188
- 224
-
11Using the JAR manifest option in `shorten command line` worked for me. – Andrew Chelix Nov 30 '20 at 21:26
-
When did an upgrade to Android Studio 4.2 I faced this same issue as @AndrewChelix mentioned "using the JAR manifest option" fixes the problem – handlerFive May 21 '21 at 08:31
If you use JDK version from 9+, you should select
Run > Edit Configurations... > Select JUnit template.
Then, select @argfile (Java 9+) as in the image below.
If you don't see the Shorten command line, then just clicking on Modify options menu as below, and select the Shorten command line
Please try it. Good luck friends.

- 1,474
- 9
- 14
Add <property name="dynamic.classpath" value="true" />
to the .idea/workspace.xml
file under the <component name="PropertiesComponent">
tag. That worked for me.

- 164
- 1
- 9
-
+1. Setting to classpath file in shorten command line config does not seem to work on my end but this does. – Mike Diente Jun 17 '21 at 11:07
Follow this steps and select "classpath.file" option from the dropdown list given in shorten command line category.

- 337
- 4
- 14
In my case, the error was:
Error running 'MasterFileGenerator':
Command line is too long. Shorten command line for StagingFileGenerator or also for Application default configuration.
The solution was to switch to go to "Run/Debug Configurations" and switch from user-local default: none - java [options] className [args]
to JAR manifest - java -cp classpath.jar className [args]
.

- 6,915
- 14
- 67
- 103
To have it persisted:
- Open Intellj
- ctrl+shift+n
- Type workspace.xml
- Find component name="PropertiesComponent" tag
- a) in case there are list of properties, add
<property name="dynamic.classpath" value="true" />
b) in case there is keyToString json, add new line in the map:
"dynamic.classpath": "true"
(remember about comma in the upper line)
- (optional) If you want to have this config enabled also in another project immediately, restart intellj

- 21
- 3