如何在 IntelliJ 中为整个项目配置 "Shorten command line" 方法

How to configure "Shorten command line" method for whole project in IntelliJ

当我 运行 测试时,我收到错误 "Command line is too long"。 如果我将 Run/Debug 配置中的 "Shorten command line" 方法设置为特定方法的 "JAR manifest" 或 class,它会起作用,但我如何为整个项目设置它或是否存在IDE 全局设置?

您可以设置一种默认方式来缩短命令行,并将其用作 changing the default JUnit Run/Debug 配置模板进行进一步配置的模板。然后,您在项目中创建的所有新 Run/Debug 配置都将使用相同的选项。

这里是related blog post关于可配置的命令行缩短器选项。

在您的 .idea 文件夹中,更改 workspace.xml 文件

添加

<property name="dynamic.classpath" value="true" />

  <component name="PropertiesComponent">
.
.
.
  </component>

例子

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

如果您没有看到,请自行添加

 <component name="PropertiesComponent">
    <property name="dynamic.classpath" value="true" />
  </component>

Intellij 2018.2.5

运行 => 编辑配置 => 在左侧选择节点 => 展开环境 => 缩短命令行选项 => 选择类路径文件或 JAR 清单

感谢 Rajesh Goel Android Studio:

运行 > 编辑配置...

Select 测试(优于 select 父测试 class)并将 Shorten command line: 选项设置为 classpath file。然后确定(或应用,确定)。

如果您使用 9+ 的 JDK 版本,您应该 select

运行 > 编辑配置... > Select JUnit模板。

然后,select @argfile (Java 9+) 如下图。

如果您没有看到缩短命令行,那么只需单击下面的修改选项菜单,然后select 缩短命令行

请试一试。祝朋友们好运。

最新的 2020 版本默认没有缩短命令行选项,我们需要从配置中添加该选项。

运行>编辑配置>Select相应的运行配置然后点击修改选项 用于将缩短的命令行配置添加到 UI。

Select 缩短命令行选项

现在从缩短命令行选项中选择 jar 清单

<property name="dynamic.classpath" value="true" /> 添加到.idea/workspace.xml 文件的<component name="PropertiesComponent"> 标签下。这对我有用。

按照此步骤和select“缩短命令行类别”下拉列表中的“classpath.file”选项进行操作。