2

Say I have the following profile defined in my ~/.m2/settings.xml file

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

Now I want to download a home-built apr-1.6.2.tar.gz arfifact from the thirdparty repository id defined in the settings.xml, so in my pom.xml file I have

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

I see examples of profiles online, but they're all defined in the pom.xml itself, but that's not what I want to do. I just want to use a URL defined in my settings.xml profile inside my pom.xml file.

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • Define a property in your settings.xml and use that. But I don't think that's a good idea...furthermore I would ask why are you downloading a file separately ... – khmarbaise Nov 18 '17 at 11:19
  • You're correct I don't want a property, but a profile. I'm downloading this file so I can compile, build, and package it into an RPM. – Chris F Nov 18 '17 at 15:06
  • If you are using apr which itself should be available via RPM dependencies? Isn't it? Apart from that I'm not sure if it's really a good idea to use Maven in such cases... – khmarbaise Nov 18 '17 at 16:43
  • apr is just an example. It can be ANY file. – Chris F Nov 20 '17 at 18:45

2 Answers2

2

you can achieve this in multiple ways

  1. Set active profile in 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. Set active profile from CLI

    mvn clean verify -P artifactory

  3. set active profile as default in 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>
    

For more info on these options check maven page

TrafLaw
  • 308
  • 1
  • 9
-2

activate them via command-line (-P <name>) or with triggers what ever you like. but ask yourself, whether it is the right place to locate your profile. for further info look at the documentation:

1.Maven Doc

  1. same question?

  2. Profile activation in Eclipse

André
  • 172
  • 13
  • None of the links provided answer the specific question I asked. Like, where did I ask about Eclipse? – Chris F Nov 18 '17 at 06:33
  • hm I thought your question is about activating a profile in your build, thats the reason ... – André Nov 24 '17 at 21:52