263

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?

13 Answers 13

294

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

Sign up to request clarification or add additional context in comments.

3 Comments

This 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 <project_name>.iws file. If you don't have a .idea folder, search for an .iws file in your project.
This didn't work for me, although obviously working for others so not sure why
you can do this in <project_name>.iml file as well if you cant find .iws file or /.idea directory
176

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

Screen shot of Run/Debug Configuration showing the command line options

3 Comments

This solution has to be set new every time you run a single test you haven't run before
You 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.
Yup! This worked like a charm for me for Android tests! Thank you!
130

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.

6 Comments

It doesnt work anymore in the new version because the option got deleted. How to do it now?
The 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".
select option "classpath file" works and I would suggest to include this option in the answer for newer version of IDE.
Hey @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
In IJ version 2021, the "Shorten command line" option is hidden by default. To see it, choose "Modify options" -> check "Shorten command line".
|
69

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. enter image description here

Select the shorten command line option enter image description here

Now choose jar manifest from the shorten command line option enter image description here

2 Comments

I could not found nay solutions because all answer was a old version! This really help me! thanks a lot!
For the latest versions of IntelliJ, this works
54

Thanks to Rajesh Goel in Android Studio:

Run > Edit Configurations...

enter image description here

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).

enter image description here

2 Comments

Using the JAR manifest option in shorten command line worked for me.
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
19

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.

enter image description here

If you don't see the Shorten command line, then just clicking on Modify options menu as below, and select the Shorten command line

enter image description here

Please try it. Good luck friends.

Comments

9

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

1 Comment

+1. Setting to classpath file in shorten command line config does not seem to work on my end but this does.
5

Follow this steps and select "classpath.file" option from the dropdown list given in shorten command line category. enter image description here

enter image description here

1 Comment

This is the better answer by far. No need to manually change config files. Thank you
2

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].

enter image description here

Comments

1

To have it persisted:

  1. Open Intellj
  2. ctrl+shift+n
  3. Type workspace.xml
  4. Find component name="PropertiesComponent" tag
  5. 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:

&quot;dynamic.classpath&quot;: &quot;true&quot; (remember about comma in the upper line)

  1. (optional) If you want to have this config enabled also in another project immediately, restart intellj

Comments

0

Idea 2022+ Run > Edit Configurations... > Edit configuration templates.. (ibottom left link in modal window) > choose your template > Modify options > Shorten command line

Comments

0

My case for Intellij: Search -> Edit Configurations -> Shorten command line -> JAR manifest -> Apply

Comments

0

For latest intellij-IDEA 2023+/2024+

  1. From navigation bar, go to RUN -> and Edit Configurations

Run Edit configurations

  1. Then Modify Options and by default the Shorten Command line is disabled, need to select/click as tickmark

Shorten Command line

  1. Then select - Shorten Command line as JAR Manifest

Shorten Command line - JAR Manifest

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.