Intellij为运行配置设置运行时变量

mas*_*ter 3 intellij-idea

我有maven运行配置,我打电话给:

liquibase:rollback -Dliquibase.rollbackCount=1 -Dliquibase.clearCheckSums=true
Run Code Online (Sandbox Code Playgroud)

在运行配置本身而不是编辑配置之前,有没有办法显示一些弹出窗口来提供rollbackCount?

dav*_*993 6

IntelliJ本身无法提示您输入命令行参数.但您可以通过解决方法实现此目的:

1)创建一个.bat文件,提示您输入并创建一个简单的属性文件(假设您正在使用Windows)

@echo off
set /p id="ID: "
echo liquibase.rollbackCount=%id% > config.properties
Run Code Online (Sandbox Code Playgroud)

2)从maven加载属性文件.这使用了maven的属性插件.如果您已经在使用该插件,则不得插入依赖项.

<dependency>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
</dependency> 
...
  <build>    
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-1</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>${basedir}/config.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
   </plugins>
Run Code Online (Sandbox Code Playgroud)

3)在运行maven之前执行bat

  1. 编辑运行配置
  2. 将"外部工具"添加到"发布之前"
  3. 将工作目录设置为:$ProjectFileDir$和编程到您的.bat文件

在IntelliJ中运行程序时,现在应该打开命令行,批处理文件要求提供ID.然后将写入属性文件,maven执行并加载该文件.


Jim*_*ins 5

试试这个:

  • 在"运行/调试配置"对话框中配置Maven作业
  • 设置Show this page我的屏幕截图中显示的复选框
  • 当您调用运行配置时,会出现一个对话框,应该可以编辑该字段command line或其他内容

maven任务的运行/调试配置