在Maven 3.5.2中,如何在我的pom.xml文件中使用settings.xml文件中定义的配置文件?

时间:2017-11-17 18:49:44

标签: maven maven-3 maven-plugin

说我在〜/ .m2 / settings.xml文件中定义了以下配置文件

 <profiles>
   <profile>
     <id>artifactory</id>
     </repositories> 
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>thirdparty</id>
          <name>scscm-thirdparty</name>
          <url>http://www.mycompany.com/artifactory/my-thirdparty-repo</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

现在我想从settings.xml中定义的第三方存储库id下载一个自制的apr-1.6.2.tar.gz arfifact,所以在我的pom.xml文件中我有

<artifactId>apr</artifactId>
<groupId>com.company</groupId>
<version>1.6.2</version>
<packaging>pom</packaging>

<dependencies>
  <dependency>
    <groupId>org.apache</groupId>
    <artifactId>apr</artifactId>
    <version>1.6.2</version>
    <type>tar.gz</type>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
    <groupId>com.googlecode.maven-download-plugin</groupId>
    <artifactId>download-maven-plugin</artifactId>
    <version>1.4.0</version>
    <executions>
      <execution>
        <id>apr</id>
        <phase>pre-integration-test</phase>
          <goals>
            <goal>wget</goal>
          </goals>
          <configuration>
            # HOW DO I SPECIFY URL FROM PROFILE HERE????
           <unpack>false</unpack>
         </configuration>
      </execution>
    </executions>
    </plugin>
  </plujgins>
</build>

我在线查看配置文件的示例,但它们都是在pom.xml本身中定义的,但这不是我想要做的。我只想使用我的pom.xml文件中的settings.xml配置文件中定义的URL。

2 个答案:

答案 0 :(得分:1)

你可以通过多种方式实现这一目标

  1. 在Settings.xml中设置活动配置文件

    SparkConf
  2. 从CLI设置活动配置文件

    mvn clean verify -P artifactory

  3. 在Settings.xml中将活动配置文件设置为默认值

    sc.getConf.get("spark.executorEnv.FOO")
    
  4. 有关这些选项的详细信息,请查看maven

答案 1 :(得分:-2)

通过命令行(-P <name>)或触发器激活它们。但问问自己,这是否是找到您的个人资料的正确位置。有关详细信息,请查看文档:

1。Maven Doc

  1. same question?

  2. Profile activation in Eclipse