【问题标题】:Acessing the fully qualified path of a target folder within a groovy script in maven在 maven 的 groovy 脚本中访问目标文件夹的完全限定路径
【发布时间】:2017-08-13 15:44:29
【问题描述】:

如何访问实际的完全限定路径,以便在 groovy 脚本中向其写入文件?

属性

<properties>
    <gen.resources.config>target/generated-resources/config</gen.resources.config>
</properties>

GMavenPlus 插件


  <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>groooovy</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <scripts>
                    <script><![CDATA[
  def filePath = "${gen.resources.config}/hello.json"

  println(filePath)

  new File(filePath).write(output)

                    ]]></script>
                </scripts>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <!-- any version of Groovy \>= 1.5.0 should work here -->
                    <version>2.4.7</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </plugin>

【问题讨论】:

  • 不完全确定如何更好地格式化,抱歉

标签: maven groovy gmavenplus


【解决方案1】:

试试下面的代码:

<scripts>
    <script><![CDATA[
        def output="test"
        def filePath = "${project.basedir}/${project.properties.getProperty('gen.resources.config')}/hello.json"

        println(filePath)

        new File(filePath).write(output)
        ]]></script>
</scripts>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多