maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriele Columbro" <g.colum...@sourcesense.com>
Subject Re: Limiting Plugin Inheritence
Date Mon, 01 Dec 2008 20:51:58 GMT
I solved this problem using profiles and working on the fact that a profile
is inherited only when it's defined also in the child pom, so not definying
your plugin/plugins configuration in the main build.

I have a project structure composed of multiple (WAR and JAR) artifacts with
cross dependencies and a super pom, something like:

project_root
                    |-- project_war1
                    |-- project_war2
                    |-- project_jar1

So basically I have a (for jboss using cargo) a super pom which defines all
cargo plugin configuration in a profile called 'deploy' , which goes
something like this:

<profile>
            <!-- Profile to deploy to a local jboss instance, due to
http://jira.codehaus.org/browse/CARGO-416 -->
            <id>deploy</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <configuration>
                            <container>
                                <containerId>jboss4x</containerId>
                                <type>remote</type>
                            </container>
                            <configuration>
                                <type>runtime</type>
                                <properties>

<cargo.hostname>${cargo.hostname}</cargo.hostname>

<cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>

<cargo.remote.password>${cargo.remote.password}</cargo.remote.password>

<cargo.remote.username>${cargo.remote.username}</cargo.remote.username>
                                </properties>
                            </configuration>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

Properties for this profile are configured in the superpom <properties>
section, which goes something like:

<properties>
        <!-- src/main/properties/<env>/application.properties is loaded for
all subproject -->
        <env>local</env>
        <cargo.hostname>localhost</cargo.hostname>
        <cargo.remote.password/>
        <cargo.remote.username/>
        <cargo.servlet.port>8080</cargo.servlet.port>
</properties>


Then, for every project which I'd like to deploy I configure in the specific
child pom an <inherited> profile with same id ("deploy" in our case) as this
one which actually binds the specified plugin configuration to an actual
lifecycle phase (typically in the pre-integration-test):

        <profile>
            <id>deploy</id>
            <build>
                <plugins>
                    <plugin>
                            <groupId>org.codehaus.cargo</groupId>
                            <artifactId>cargo-maven2-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>deploy</id>
                                    <!-- This works as expected -->
                                    <inherited>true</inherited>
                                    <goals>
                                        <goal>deployer-redeploy</goal>
                                    </goals>
                                    <phase>pre-integration-test</phase>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
        </profile>

So basically running my build from the super pom by explicitly activating
the plugin (because according to [1] inherited profiles only gets run  if
explicitly called by id with -P option and not with the other activation
methods described here [2] ):

mvn clean install -P deploy

I get only the selected sub projects to be deployed with cargo while other
projects (that do not inherit the profile) will only run the default build
lifecycle (so with neither cargo configuaration nor binding it to a phase).

As a side note, I also use "environmental" profiles (using the <env>
variable) so that different cargo (buildtime) properties and and application
(runtime) properties are selected, e.g. :

    <profile>
            <id>accpt</id>
            <properties>
                <cargo.hostname>accpt.yourcompany.com</cargo.hostname>

<cargo.remote.password>accptJbossPassword</cargo.remote.password>

<cargo.remote.username>accptJbossUsername</cargo.remote.username>
                <cargo.servlet.port>80</cargo.servlet.port>
                <env>test</env>
            </properties>
        </profile>

which allows me to have my selected subprojects deployed to different
environment by combining profiles in a quite short command line (considering
maven standards :) :

mvn clean install -Pdeploy,accpt

Hope a lot this helps! And hopefully someone can come with some even easier
and shorter way to express this non trivial requirement.

Gab



[1] http://jira.codehaus.org/browse/MNG-3228
[2]
http://maven.apache.org/guides/introduction/introduction-to-profiles.html



2008/12/1 euqaz <online@euqaz.net>

>
> I'm trying to port a project over to Maven.   We've been developing an
> enterprise application in eclipse and have the following projects:
>
> projectname-beans  (all session beans and dependent classes)
> projectname-entities (all jpa entities)
> projectname-lib (all remote interfaces and dto objects)
> projectname-client-api (the api that clients program against using dto)
> projectname-core (the ear definition)
> projectname-parent (the maven parent project)
>
> currently I have just about everything working (i think).  i can build,
> test, and package just fine.  i can even deploy the ear to glassfish using
> the glassfish plugin but this is where i'm trying to make some improvements
> to the build and coming up short...
>
> directory structure:
>
> projectname-parent/
>   projectname-beans/
>   projectname-entities/
>   projectname-lib/
>   projectname-client-api/
>   projectname-core/
>
> beans, entities, lib, client-api, core are all <modules> or parent.
>
> I'm trying to define the glassfish plugin in the parent pom and be able to
> run: projectname-parent> mvn glassfish:deploy
>
> and have it deploy the projectname-core.ear
>
> after succesfully deploying the ear it then tries to run the
> glassfish:deploy goal on each module (client-lib, api, beans, entites)
> which
> fails.  (well, actually deploy doesn't fail - it doesn't do anything...but
> glassfish:undeploy does fail.  in reality, the main problem is that
> glassfish plugin is running against all modules)
>
> how can I define a plugin in the parent that does not run against each
> child
> module?
>
> snip of parent pom:
>
> <!-- parent pom snippet -->
> <project>
> ...
>        <build>
>           <plugins>
>              <plugin>
>                 <groupId>org.glassfish.maven.plugin</groupId>
>                 <artifactId>maven-glassfish-plugin</artifactId>
>                 <version>2.1</version>
>
>                 <configuration>
>
>  <glassfishDirectory>${glassfish.home}</glassfishDirectory>
>                    <domainDirectory>${dev.domain.dir}</domainDirectory>
>                    <autoCreate>false</autoCreate>
>                    <echo>false</echo>
>                    <terse>false</terse>
>                    <interactive>false</interactive>
>                    <user>admin</user>
>
> <passwordFile>${dev.domain.dir}/${dev.domain.name
> }/dev-domain-pw-file</passwordFile>
>                    <domain>
>                       <name>${dev.domain.name}</name>
>                       <adminPort>4848</adminPort>
>                       <httpPort>8080</httpPort>
>                       <httpsPort>8443</httpsPort>
>                       <iiopPort>3700</iiopPort>
>                       <jmsPort>7676</jmsPort>
>                    </domain>
>                    <components>
>                       <component>
>                          <name>${projectname.core.name}</name>
>
> <artifact>${projectname.core.name}/${project.build.directory}/${
> projectname.core.name}-${project.version}.ear</artifact>
>                       </component>
>                    </components>
>                 </configuration>
>              </plugin>
>           </plugins>
>   </build>
> ...
> </project>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Limiting-Plugin-Inheritence-tp20778618p20778618.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Gabriele Columbro
Alfresco ECM Product Strategy Consultant
+31 627 565 103
Sourcesense - Making sense of open Source (http://www.sourcesense.com)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message