用Maven部署一个zip文件

问题描述

我正在尝试使用deploy:deploy-file将zip文件部署到nexus,但是maven对此仍然不满意,并且抱怨缺少项目/ pom文件。下面是代码段和调试日志

$params =
            @(
                "deploy:deploy-file","-X","-e","-DartifactId=${env:ZIP_PREFIX}","-Dmaven.wagon.provider.http=httpclient","-Durl=http://abc-nexus.repo.net:9081/repository/releases-prod-dist","-DrepositoryId=releases-prod-dist","-DgroupId=$nexusPath","-Dversion=$fullVersion","-Dpackaging=zip","-Dfile=$reviewArea\$zipName"
            )

            start-process "java" -ArgumentList @("-version") -Wait -NoNewWindow
            start-process "mvn" -ArgumentList @("-version") -Wait -NoNewWindow
            

            Write-Output "start-process mvn -NoNewWindow -Wait -ArgumentList ${params}"
            start-process mvn -NoNewWindow -Passthru -Wait -ArgumentList $params

2020-09-11T06:17:27.7943241Z [INFO] Scanning for projects...
2020-09-11T06:17:27.9140863Z [DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
2020-09-11T06:17:27.9466573Z [DEBUG] Looking up lifecycle mappings for 
packaging pom from ClassRealm[plexus.core,parent: null]
2020-09-11T06:17:27.9641628Z [INFO] ------------------------------------------------------------------------
2020-09-11T06:17:27.9643764Z [INFO] BUILD FAILURE
2020-09-11T06:17:27.9645595Z [INFO] ------------------------------------------------------------------------
2020-09-11T06:17:27.9684029Z [INFO] Total time: 0.250 s
2020-09-11T06:17:27.9689684Z [INFO] Finished at: 2020-09-10T23:17:27-07:00
2020-09-11T06:17:28.0604956Z [INFO] Final Memory: 6M/245M
2020-09-11T06:17:28.0608153Z [INFO] ------------------------------------------------------------------------
2020-09-11T06:17:28.0695335Z [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\AzureRemoteAgent\_work\r16\a). Please verify you invoked Maven from the correct directory. -> [Help 1]
2020-09-11T06:17:28.0700315Z org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a project to execute but there is no POM in this directory (C:\AzureRemoteAgent\_work\r16\a). Please verify you invoked Maven from the correct directory.
2020-09-11T06:17:28.0703641Z     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:85)
2020-09-11T06:17:28.0708399Z     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:309)
2020-09-11T06:17:28.0710747Z     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
2020-09-11T06:17:28.0712639Z     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
2020-09-11T06:17:28.0714330Z     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
2020-09-11T06:17:28.0716002Z     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
2020-09-11T06:17:28.0717718Z     at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
2020-09-11T06:17:28.0719285Z     at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
2020-09-11T06:17:28.0721040Z     at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
2020-09-11T06:17:28.0723365Z     at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
2020-09-11T06:17:28.0725220Z     at java.lang.reflect.Method.invoke (Method.java:498)
2020-09-11T06:17:28.0727008Z     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
2020-09-11T06:17:28.0729074Z     at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
2020-09-11T06:17:28.0731080Z     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
2020-09-11T06:17:28.0733229Z     at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

解决方法

在Powershell中,每个参数都必须用双引号引起来。我最后在没有变量的参数周围加上了单引号,在没有参数的地方加上了反引号。这样可以保留参数中的双引号,并扩展变量。

 $params =
            @(
                '"deploy:deploy-file"','"-X"','"-e"',"`"-DartifactId=${env:ZIP_PREFIX}`"",'"-Dmaven.wagon.provider.http=httpclient"','"-Durl=http://abc-nexus.repo.net:9081/repository/releases-prod-dist"','"-DrepositoryId=releases-prod-dist"',"`"-DgroupId=$nexusPath`"","`"-Dversion=$fullVersion`"",'"-Dpackaging=zip"',"`"-Dfile=$parentDir\$zipName`""
            )