首页 > 解决方案 > 进行 maven 配置时 setting.xml 和 pom.xml 出了什么问题

问题描述

我正在尝试探索 maven 作为下载工具,因为这有助于本地缓存以及连接中央/远程存储库。我能够从远程存储库下载工件。但是每次下载到目标位置时,它看起来都不是 .m2 存储库或更新。我相信我在 setting.xml 或 pom.xml 中缺少一些设置。

我打算下载以检查本地存储库中是否已经存在工件可以是 .m2 或预定义的,如果没有,则仅从工件下载。

使用的 Maven 命令:

mvn install pre-integration-test -f pom_download.xml -settings settings.xml -Dmayank=test.txt

输出 :

[INFO] --- wagon-maven-plugin:2.0.0:download-single (download-test-data) @ testdownload ---
[INFO] Downloading: https://artifactory.com/artifactory/test.txt to C:\downloads\test.txt
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  30.830 s
[INFO] Finished at: 2019-10-04T06:34:40-07:00
[INFO] ------------------------------------------------------------------------

设置.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     | -->
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>https</protocol>
      <host></host>
      <port></port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>

    <proxy>
      <id>optional_1</id>
      <active>true</active>
      <protocol>http</protocol>
      <host></host>
      <port></port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
  </proxies>
<localRepository>C:\repo_mayank</localRepository>
  <servers>
    <server>
      <id>ubit-artifactory-or</id>
      <username>mayank</username>
      <password>xxxxx</password>
    </server>
  </servers>
  <profiles>
    <profile>
    <id>artifactory</id>
        <repositories>
            <repository>
                <id>xxxx</id>
                <name>xxxx</name>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                    <checksumPolicy>fail</checksumPolicy>
                </snapshots>
                <url>https://artifactory.com/</url>
                <layout>default</layout>
            </repository>
        </repositories>
        <mirrors>
            <mirror>
                <id>our-server-repo</id>
                <name>C:\repo_mayank</name>
                <url>https://artifactory.com/</url>
                <mirrorOf>*</mirrorOf>
            </mirror>
        </mirrors>
    </profile>
  </profiles>
  <activeProfiles>
   <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

Pom.xml

?xml version='1.0' encoding='utf8'?>
<project>
    <groupId>com.mayank</groupId>
    <artifactId>testdownload</artifactId>
    <version>1.0</version>
    <modelVersion>4.0.0</modelVersion>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>2.0.0</version>

                <executions>
                    <execution>
                        <id>download-test-data</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>download-single</goal> 
                        </goals>
                        <configuration>
                            <task>
                                <echo> Hello World !!!</echo>
                            </task>

                            <serverId>artifactory</serverId>

                            <url>https://artifactory.com</url>
                            <fromFile>${mayank}</fromFile>
                            <toDir>C:\downloads</toDir>

                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <mayank> hello </mayank>
    </properties>

</project>

标签: javamavenmaven-3

解决方案


看起来 maven wagon 插件根本不使用 maven 缓存。如果要下载链接到项目的工件,可以使用 maven 依赖插件并使用 copy-dependencies 目标。如果您只想复制一些工件,请使用复制目标。更多信息:http ://maven.apache.org/plugins/maven-dependency-plugin/无论哪种方式,您都必须在 pom 中指定您想要的内容。


推荐阅读