簡體   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