You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by John Didion <Jo...@loudeye.com> on 2006/04/07 05:05:03 UTC

Can I activate a profile based on module type?

I have a project with several different types of modules - some are
libraries (stand-alone jars), some are wars, some are executables (jars
plus some extra plugins to generate batch files and create an assembly).
I would like to put the configuration for all these different project
types in to my top-level pom, and then have each module activate only
the plugin configurations that apply to its type. Profiles seem a
natural way to do this, but I can't find any way to explicitly activate
them from a module.

Using the activeProfiles element in settings.xml doesn't make sense
since the profile I want to activate will differ depending on the
module. I tried using a profiles.xml and setting the activeProfiles
there, but unfortunately that only applies to the profiles defined in
profiles.xml.

Is there another way to do what I want?

Here's an example:

pom.xml
-------------
<project>
 
  <groupId>test</groupId>
  <artifactId>parent</artifactId>    

  <profile>
    <id>library</id>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>foo</groupId>
          <artifactId>foo</artifactId>
          <configuration>
              ...
           </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </profile>

  <profile>
    <id>webapp</id>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>foo</groupId>
          <artifactId>foo</artifactId>
          <configuration>
              ... (different than the library profile's configuration)
           </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </profile>

</project> 

child/pom.xml
---------------------
<project>
  <parent>
    <groupId>test</groupId>
    <artifactId>parent</artifactId>
  </parent>
  <groupId>test</groupId>
  <artifactId>child</artifactId>

  ...what do I do here to activate the library profile?...
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Can I activate a profile based on module type?

Posted by Tim Kettler <ti...@udo.edu>.
Hi,

I never tried this but I think this could/should work:

1. You define the profiles in your parent pom like this

<profiles>
   <profile>
     <id>library</id>
     <activation>
       <property>
         <name>moduletype</name>
         <value>jar</value>
       </property>
     </activation>
     ...
   </profile>

   <profile>
     <id>webapp</id>
     <activation>
       <property>
         <name>moduletype</name>
         <value>war</value>
       </property>
     </activation>
     ...
   </profile>
</profiles>

2. In your modules you then define the property as needed

<properties>
   <moduletype>lib</moduletype>
</properties>

The most elegant solution would be to not use a custom defined property at all but the 
vaule of the <packaging/> element of the module poms but I don't know if the content is 
made available as a property.

-Tim

John Didion schrieb:
> I have a project with several different types of modules - some are
> libraries (stand-alone jars), some are wars, some are executables (jars
> plus some extra plugins to generate batch files and create an assembly).
> I would like to put the configuration for all these different project
> types in to my top-level pom, and then have each module activate only
> the plugin configurations that apply to its type. Profiles seem a
> natural way to do this, but I can't find any way to explicitly activate
> them from a module.
> 
> Using the activeProfiles element in settings.xml doesn't make sense
> since the profile I want to activate will differ depending on the
> module. I tried using a profiles.xml and setting the activeProfiles
> there, but unfortunately that only applies to the profiles defined in
> profiles.xml.
> 
> Is there another way to do what I want?
> 
> Here's an example:
> 
> pom.xml
> -------------
> <project>
>  
>   <groupId>test</groupId>
>   <artifactId>parent</artifactId>    
> 
>   <profile>
>     <id>library</id>
>     <pluginManagement>
>       <plugins>
>         <plugin>
>           <groupId>foo</groupId>
>           <artifactId>foo</artifactId>
>           <configuration>
>               ...
>            </configuration>
>         </plugin>
>       </plugins>
>     </pluginManagement>
>   </profile>
> 
>   <profile>
>     <id>webapp</id>
>     <pluginManagement>
>       <plugins>
>         <plugin>
>           <groupId>foo</groupId>
>           <artifactId>foo</artifactId>
>           <configuration>
>               ... (different than the library profile's configuration)
>            </configuration>
>         </plugin>
>       </plugins>
>     </pluginManagement>
>   </profile>
> 
> </project> 
> 
> child/pom.xml
> ---------------------
> <project>
>   <parent>
>     <groupId>test</groupId>
>     <artifactId>parent</artifactId>
>   </parent>
>   <groupId>test</groupId>
>   <artifactId>child</artifactId>
> 
>   ...what do I do here to activate the library profile?...
> </project>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org