如何在Maven中使用Groovy插件访问变量

时间:2018-10-16 18:56:51

标签: reactjs maven groovy gmaven-plugin gmaven

我在子模块中有一个带有React的应用程序,我想使用父模块中存在的node.exe。

在父POM中,我定义了一个变量,其变量为node.exe

for ind in range(dfC.shape[0]):
   if dfC.loc[ind, 'SOURCE'] == 'dfA':
       "do what you want to dfA"
   if dfC.loc[ind, 'SOURCE'] == 'dfB':
           "do what you want to dfB"

不好。:我想在nodeBase变量中使用$ {project.basedir}

然后我尝试在子POM中访问这些变量,以将其作为参数传递给ProcessBuilder方法:

<properties>
    <project.name>Corretor Online</project.name>
    <nodeBase>C:/col/COL</nodeBase>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

但是我发现了这个错误:

  

[错误]无法在项目col-backoffice-war:groovy.lang.MissingPropertyException上执行目标org.codehaus.groovy.maven:gmaven-plugin:1.0:execute(webpack):无此类属性:class的nodeBase: script1539714060887-> [帮助1]

如果我从“ nodeBase”更改为“ $ {nodeBase},我会收到此错误:

  

[错误]无法在项目col-backoffice-war上执行目标org.codehaus.groovy.maven:gmaven-plugin:1.0:execute(webpack):启动失败,脚本1539714572018.groovy:2:意外字符:'# '@第2行,第134列。

但是,如果我输入原义路径,就可以构建。

<plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <executions>
                <execution>
                    <id>webpack</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source><![CDATA[
                                println "Compiling client code..."
                                def webpack = new ProcessBuilder(["" + nodeBase + "/node/node", "" + nodeBase + "/node_modules/webpack/bin/webpack.js", "-p", "&#45;&#45;progress", "&#45;&#45;bail"]).inheritIO().directory(project.getBasedir())
                                def env = webpack.environment()
                                env.put("WAR_NAME", project.build.finalName)
                                def proc_webpack = webpack.start()
                                proc_webpack.waitForOrKill(120000)
                                if(proc_webpack.exitValue() != 0)
                                    throw new org.apache.maven.plugin.MojoFailureException("Error compiling client code")
                            ]]></source>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我找不到解决方案,请您协助我访问该变量?

非常感谢!

1 个答案:

答案 0 :(得分:0)

我弄清楚了这个问题。

有必要将参数放在引号中,如下例所示。

    def webpack = new ProcessBuilder("${nodeBase}" + "/node/node", "C:/col/COL/node_modules/webpack/bin/webpack.js", "-p", "&#45;&#45;progress", "&#45;&#45;bail"]).inheritIO().directory(project.getBasedir())