如何在 IntelliJ 中为整个项目配置“缩短命令行”方法

问题描述 投票:0回答:11

当我运行测试时,我收到错误“命令行太长”。 如果我将运行/调试配置中的“缩短命令行”方法设置为特定方法或类的“JAR 清单”,它会起作用,但如何为整个项目设置它,或者是否有 IDE 全局设置?

testing intellij-idea settings
11个回答
293
投票

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

社区编辑:这个解决方案似乎不适用于较新版本的IDE,现在

PropertiesComponent
的格式不同了。如果这是你的情况,那么这个答案应该有效


171
投票

Intellij 2018.2.5

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


127
投票

您可以通过更改默认 JUnit 运行/调试配置模板来设置默认方式来缩短命令行并将其用作进一步配置的模板。然后,您在项目中创建的所有新运行/调试配置都将使用相同的选项。

这是关于可配置命令行缩短选项的相关博客文章


69
投票

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

运行 > 编辑配置 > 选择相应的运行配置,然后单击 修改选项,将缩短的命令行配置添加到 UI。

选择缩短命令行选项

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


53
投票

感谢 Rajesh Goel 在

Android Studio
:

运行 > 编辑配置...

选择一个测试(最好选择父测试类)并将

Shorten command line:
选项设置为
classpath file
。然后确定(或应用,确定)。


18
投票

如果您使用 JDK 9+ 版本,则应选择

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

然后,选择@argfile (Java 9+),如下图所示。

如果您没有看到缩短命令行,则只需单击如下所示的修改选项菜单,然后选择缩短命令行

请尝试一下。祝朋友好运。


9
投票

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


5
投票

按照此步骤操作,从缩短命令行类别中给出的下拉列表中选择“classpath.file”选项。


2
投票

就我而言,错误是:

Error running 'MasterFileGenerator':
Command line is too long. Shorten command line for StagingFileGenerator or also for Application default configuration.

解决方案是切换到“运行/调试配置”并从

user-local default: none - java [options] className [args]
切换到
JAR manifest - java -cp classpath.jar className [args]


0
投票

让它坚持下去:

  1. 打开Intellij
  2. ctrl+shift+n
  3. 输入workspace.xml
  4. 找到组件名称=“PropertiesComponent”标签
  5. a) 如果有属性列表,请添加

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

b) 如果存在 keyToString json,请在地图中添加新行:

&quot;dynamic.classpath&quot;: &quot;true&quot;
(记住上面一行的逗号)

  1. (可选)如果您想立即在另一个项目中启用此配置,请重新启动 intellj

0
投票

理念2022+ 运行 > 编辑配置... > 编辑配置模板..(模式窗口中的左下角链接)> 选择模板 > 修改选项 > 缩短命令行

© www.soinside.com 2019 - 2024. All rights reserved.