本文介绍了在POM文件中使用Groovy进行分隔符切换对于不同的开发人员来说是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在POM文件中使用了一小段Groovy代码,用正斜杠分隔符替换主基础目录中的反斜杠分隔符。
有关更多信息,请参阅这篇文章:



然而,我们遇到的问题是,该链接的建议groovy在一台开发机器上工作正常,但不在另一台机器上。 p>

对于第一个开发人员有用的是:(链接的帖子中提到的代码)

 code> pom.properties [ 'main.basedir'] = project.basedir.absolutePath.replace( '\\', '/'); 

其他开发人员的工作原理如下:

  pom.properties ['main.basedir'] = project.basedir.absolutePath.replace('\','/'); 

(注意单个反斜杠)



使用双反斜杠时第二个开发人员看到的错误是:

  [INFO] BUILD FAILURE 
[INFO] -------------------------------------------------- ----------------------
[INFO]总时间:1:15.096s
[INFO]完成于:Tue Sep 03 16 :54:18 BST 2013
[INFO] Final Memory:36M / 298M
[INFO] ------------------------ ------------------------------------------------
[ERROR]无法执行目标org.codehaus.gmaven:gmaven-plugin:1.5:在项目bonus-wallet-amq-tests上执行(setproperty):启动失败,script1378223658221.groovy:1:expecting'''found '< EOF>'@ line 1,列79.
[错误] 1错误

我们无法解决为什么第二个开发者只需要单个反斜杠。
这两个开发人员都使用Eclipse Juno,Java 1.6 Update 45,并且groovy的版本必须与POM文件中的依赖关系相同。 (版本1.6.9)



我们唯一发现的是maven的版本不同。开发人员1版本为3.0.3,开发人员2版本为3.0.5版本。然而,我们一直找不到可能与此有关的任何文档。



任何帮助将是最有益的。

解决方案

您应该按照以下方式更改代码:



pom.properties ['main.basedir' ] =
project.basedir.absolutePath.replace(File.separator,'/');



而不是手动解码文件分隔符。


We are using a small segment of Groovy code within our POM file to replace the backslash delimiters in the main base directory with forward slash delimiters.For more information on this, see this post: How to convert file separator in maven

However, the problem we have is that the suggested groovy from that link works fine on one developers machine, but not on another.

What works for the first developer is this: (The code mentioned in the linked post)

pom.properties['main.basedir']=project.basedir.absolutePath.replace('\\','/');

What works for the other developer is the following:

pom.properties['main.basedir']=project.basedir.absolutePath.replace('\','/');

(Note the single backslash)

The errors that the second developer sees when using the double backslash are:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:15.096s
[INFO] Finished at: Tue Sep 03 16:54:18 BST 2013
[INFO] Final Memory: 36M/298M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.5:execute (setproperty) on project bonus-wallet-amq-tests: startup failed, script1378223658221.groovy: 1: expecting ''', found '<EOF>' @ line 1, column 79.
[ERROR] 1 error

We can't work out why the second developer only needs the single backslash.Both developers are using Eclipse Juno, Java 1.6 Update 45 and the version of groovy must be the same as it is defined as a dependency in the POM file. (Version 1.6.9)

The only thing we found was the versions of maven being different. Developer 1 has version 3.0.3 and developer 2 has version 3.0.5. However we have been unable to find any documentation that may relate to this.

Any help would be most beneficial.

解决方案

You should change your code as follows:

pom.properties['main.basedir']=project.basedir.absolutePath.replace(File.separator,'/');

Instead of manually decode your file separator.

这篇关于在POM文件中使用Groovy进行分隔符切换对于不同的开发人员来说是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:52