Ralph
Ralph

Reputation: 4868

How to deploy maven artifacts depending on their profile?

I am using a public maven repository on Github to deploy new versions of my open source java project. The project can be built in two different versions which are defined by profile configurations in the pom.xml When I deploy my artifact the default build will be uploaded into the repository. Is it possible to deploy different maven builds depending on different profiles with the same maven version number? Or is there a concept or best practice of how to use different version numbers of a maven artifact depending on the selected profile?

Upvotes: 0

Views: 2823

Answers (1)

josh-cain
josh-cain

Reputation: 5226

Not 100% sure what you're asking, but associating a classifier with your artifacts might be what you're looking for. For instance, if you needed a 'prod' and 'stage' artifact with different profiles, you would do something like this:

<profiles>
   <profile>
     <id>stage</id>
     <build>
       <plugins>
         .
         .
         <plugin>
           <artifactId>maven-jar-plugin</artifactId>
           <executions>
             <execution>
               <phase>package</phase>
               <goals>
                 <goal>jar</goal>
               </goals>
               <configuration>
                 <classifier>stage</classifier>
               </configuration>
             </execution>
           </executions>
         </plugin>
       </plugins>
     </build>
   </profile>

Running your 'stage' profile would give you a '-stage' artifact. Although, I would argue that there are usually better ways to do this, it's not uncommon to use profiles to build for different environments. Is this what you're trying to do?

Upvotes: 1

Related Questions