繁体   English   中英

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

[英]In Maven 3.5.2, how do I use a profile defined in my settings.xml file in my pom.xml file?

说我在〜/ .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文件,因此在我的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。

您可以通过多种方式实现

  1. 在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> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> 
  2. 从CLI设置活动配置文件

    mvn clean verify -P人工制品

  3. 在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> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> 

有关这些选项的更多信息,请检查Maven页面

通过命令行( -P <name> )或使用触发器触发它们。 但请问问自己,是否是找到个人资料的合适位置。 有关更多信息,请参阅文档:

1. Maven文件

  1. 同样的问题吗?

  2. Eclipse中的概要文件激活

暂无
暂无

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

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