通过groovy执行maven部署时命令未找到错误

时间:2014-09-23 08:21:47

标签: bash maven groovy

我通过groovy执行以下命令:

def mavenCommand        = "/opt/apache-maven-3.2.2/bin/mvn";
def mavenUrl            = "-Durl=${nexusUrl}";
def mavenRepoId         = "-DrepositoryId=${nexusRepo}";
def mavenGroupId        = "-DgroupId=${groupId}";
def mavenArtefactId = "-DartifactId=${artefactName}";
def mavenVersion    = "-Dversion=${artefactVersion}";
def mavenFile       = "-Dfile=${fileLocation}";
def mavenPackaging  = "-Dpackaging=${artefactExtension}";


uploadToNexus("${mavenCommand} deploy:deploy-file ${mavenUrl} ${mavenRepoId} ${mavenGroupId} ${mavenArtefactId} ${mavenVersion} ${mavenFile} ${mavenPackaging}");

public String uploadToNexus(command){
    def uploadToNexusProc = new ProcessBuilder("/bin/sh", "-c","${command}").redirectErrorStream(true).start();
    uploadToNexusProc.waitFor();
    println uploadToNexusProc.text;
    return uploadToNexusProc.exitValue();
}

虽然在这种情况下它成功上传到nexus,但似乎总是错过最后的参数导致:

-Dpackaging=zip : command not found

我知道这是一个shell错误,由于某种原因${mavenPackaging}扩展为新行。 有人能帮我理解这个问题的原因吗?感谢。

编辑1

当我在Stackoverflow上格式化代码时,

$ {mavenPackaging“}是我的错误。它在我的代码中设置正确。现在已更新。

编辑2

如果我这样做:

println "${mavenCommand} deploy:deploy-file ${mavenUrl} ${mavenRepoId} ${mavenGroupId} ${mavenArtefactId} ${mavenVersion} ${mavenFile} ${mavenPackaging}";

我得到以下输出(突出显示问题):

/opt/apache-maven-3.2.2/bin/mvn deploy:deploy-file -Durl=http://server/content/repositories/releases -DrepositoryId=nexus -DgroupId=bogus.fake.fakeagain -DartifactId=api -Dversion=1.4.5 -Dfile=/opt/atlassian/jira/temp/api-1.4.5.zip
 -Dpackaging=zip

1 个答案:

答案 0 :(得分:0)

尝试更改以下行:

uploadToNexus("${mavenCommand} deploy:deploy-file ${mavenUrl} ${mavenRepoId} ${mavenGroupId} ${mavenArtefactId} ${mavenVersion} ${mavenFile} ${mavenPackaging"})

uploadToNexus("${mavenCommand} deploy:deploy-file ${mavenUrl} ${mavenRepoId} ${mavenGroupId} ${mavenArtefactId} ${mavenVersion} ${mavenFile} ${mavenPackaging}")