简体   繁体   English

我可以通过 Azure DevOps 工件从私有托管代理访问 Maven 中心吗?

[英]Can I reach Maven central through Azure DevOps artifacts from a private hosted agent?

I am working from a private network, trying to a buildpipeline for a Maven project.我正在使用专用网络,尝试为 Maven 项目构建管道。 To work with tools on our private network I am trying to use a Private Hosted Agent.为了在我们的私有网络上使用工具,我正在尝试使用私有托管代理。 Now I know there are some restrictions on reaching Maven Central from our network, normally we use a proxy through Nexus for this.现在我知道从我们的网络到达 Maven Central 有一些限制,通常我们通过 Nexus 使用代理。

With the new Maven Upstream feature in Azure artifacts I thought I could use this as a 'proxy'.借助 Azure 工件中的新 Maven 上游功能,我认为我可以将其用作“代理”。

Unfortunately the build is failing, it seems to try and reach Maven Central directly (not using my feed) which naturally fails.不幸的是,构建失败了,它似乎试图直接到达 Maven Central(不使用我的提要),这自然会失败。 Below my output and settings下面我的 output 和设置

我的 settings.xml

Pom.Xml,第 1 部分

Pom.xml 第 2 部分

Yaml 管道

And finally my build output:最后是我的构建 output:

2019-10-02T07:27:06.0094285Z Task         : Maven
2019-10-02T07:27:06.0094336Z Description  : Build, test, and deploy with Apache Maven
2019-10-02T07:27:06.0094403Z Version      : 3.158.0
2019-10-02T07:27:06.0094449Z Author       : Microsoft Corporation
2019-10-02T07:27:06.0094522Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/maven
2019-10-02T07:27:06.0094582Z ==============================================================================
2019-10-02T07:27:06.8762822Z [command]C:\windows\system32\reg.exe query "HKLM\SOFTWARE\JavaSoft\Java Development Kit\1.8" /v JavaHome /reg:64
2019-10-02T07:27:06.8762932Z 
2019-10-02T07:27:06.8763016Z HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8
2019-10-02T07:27:06.8763085Z     JavaHome    REG_SZ    C:\Program Files\Java\jdk1.8.0_221
2019-10-02T07:27:06.8763156Z 
2019-10-02T07:27:06.9319606Z [command]C:\windows\system32\cmd.exe /D /S /C "C:\DATA\Choco\lib\maven\apache-maven-3.6.1\bin\mvn.cmd -version"
2019-10-02T07:27:07.4696051Z Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T19:00:29Z)
2019-10-02T07:27:07.4700024Z Maven home: C:\DATA\Choco\lib\maven\apache-maven-3.6.1\bin\..
2019-10-02T07:27:07.4709043Z Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_221\jre
2019-10-02T07:27:07.4725586Z Default locale: en_US, platform encoding: Cp1252
2019-10-02T07:27:07.4726158Z OS name: "windows server 2016", version: "10.0", arch: "amd64", family: "windows"
2019-10-02T07:27:07.5446027Z SYSTEMVSSCONNECTION exists true
2019-10-02T07:27:07.7710829Z SYSTEMVSSCONNECTION exists true
2019-10-02T07:27:08.0375908Z ##[warning]The settings for the feed or repository already exists in the xml file.
2019-10-02T07:27:08.0492975Z SYSTEMVSSCONNECTION exists true
2019-10-02T07:27:08.0530287Z [command]C:\windows\system32\cmd.exe /D /S /C "C:\DATA\Choco\lib\maven\apache-maven-3.6.1\bin\mvn.cmd -f C:\DATA\Agent\_work\71\s\pom.xml -s C:\DATA\Agent\_work\_temp\settings.xml package"
2019-10-02T07:27:09.9877350Z [INFO] Scanning for projects...
2019-10-02T07:27:10.0851393Z [INFO] 
2019-10-02T07:27:10.0897285Z [INFO] ---------< com.ontestautomation.javafortesters:JavaForTesters >---------
2019-10-02T07:27:10.0941394Z [INFO] Building JavaForTesters 1.0-SNAPSHOT
2019-10-02T07:27:10.0942123Z [INFO] --------------------------------[ jar ]---------------------------------
2019-10-02T07:27:10.6741134Z Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
2019-10-02T07:27:31.8954116Z The process 'C:\DATA\Choco\lib\maven\apache-maven-3.6.1\bin\mvn.cmd' failed with exit code 1
2019-10-02T07:27:31.8954401Z [INFO] ------------------------------------------------------------------------
2019-10-02T07:27:31.8955258Z Could not retrieve code analysis results - Maven run failed.
2019-10-02T07:27:31.8955423Z [INFO] BUILD FAILURE
2019-10-02T07:27:31.8955503Z [INFO] ------------------------------------------------------------------------
2019-10-02T07:27:31.8955591Z [INFO] Total time:  21.842 s
2019-10-02T07:27:31.8955658Z [INFO] Finished at: 2019-10-02T07:27:31Z
2019-10-02T07:27:31.8955759Z [INFO] ------------------------------------------------------------------------
2019-10-02T07:27:31.8955928Z [ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.36.215] failed: Connection timed out: connect -> [Help 1]
2019-10-02T07:27:31.8956093Z [ERROR] 
2019-10-02T07:27:31.8958075Z [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
2019-10-02T07:27:31.8958201Z [ERROR] Re-run Maven using the -X switch to enable full debug logging.
2019-10-02T07:27:31.8958274Z [ERROR] 
2019-10-02T07:27:31.8958331Z [ERROR] For more information about the errors and possible solutions, please read the following articles:
2019-10-02T07:27:31.8958423Z [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
2019-10-02T07:27:33.1008909Z No test result files matching C:\DATA\Agent\_work\71\s\**\surefire-reports\TEST-*.xml were found, so publishing JUnit test results is being skipped.
2019-10-02T07:27:33.1015611Z ##[error]Build failed.
2019-10-02T07:27:33.1185161Z ##[section]Finishing: Maven ```


Anyone any ideas?

Thanks!

Can I reach Maven central through Azure DevOps artifacts from a private hosted agent?我可以通过 Azure DevOps 工件从私有托管代理访问 Maven 中心吗?

The answer should be yes.答案应该是肯定的。

The reason why it still reach Maven Central directly is that all pom files inherit from the maven super POM :之所以仍然直接到达 Maven Central 的原因是所有 pom 文件都继承自maven 超级 POM

http://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html http://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html

which contains this entry:其中包含此条目:

<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>http://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

So, we could overwrite it in your pom with Azure DevOps artifacts:因此,我们可以在您的 pom 中使用 Azure DevOps 工件覆盖它:

<repositories>
    <repository>
        <id>central</id>
        <url>https://pkgs.dev.azure.com/xxx/xxx</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>https://pkgs.dev.azure.com/xxx/xxx</url>
        <releases><enabled>false</enabled></releases>
    </pluginRepository>
</pluginRepositories>

Or you can use the maven Mirrors to to replace a particular repository with your own internal repository.或者您可以使用maven 镜像将特定的存储库替换为您自己的内部存储库。

Check more details about this issue, please check this ticket .查看有关此问题的更多详细信息,请查看此票证

Besides, you could also set the Proxies in the your pom.此外,您还可以在 pom.xml 中设置代理

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM