How to convert file separator in maven

牧云@^-^@ 提交于 2019-12-03 07:29:00

I don't think there is a non-programmatical way to do that. So I suggest a groovy one-liner with the Maven GMaven plugin (GMaven is usually the simplest way to embed programmatic code into a pom):

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <executions>
        <execution>
            <id>setproperty</id>
            <phase>validate</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
pom.properties['main.basedir']=project.parent.basedir.absolutePath.replace('\\','/');
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

Just an update to Sean's answer, I have had to make some minor adjustments in order to adapt it to the latest groovy maven plugin version:

<plugin>
          <groupId>org.codehaus.gmaven</groupId>
          <artifactId>groovy-maven-plugin</artifactId>
          <dependencies>
            <dependency>
              <groupId>org.codehaus.groovy</groupId>
              <artifactId>groovy-all</artifactId>
              <version>2.0.1</version>
            </dependency>
          </dependencies>
          <executions>
                <execution>
                    <id>setproperty</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
        project.properties['basedir']=project.parent.basedir.absolutePath.replace('\\','/');
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!