Background:
I have a layered architecture, built via a multimodule Maven project, and I
use profiles to activate which relational database (derby, mysql, or
sqlserver) & driver (derby, myssql, jtds, or msjdbc) is used for any given
build. Obviously, the derby database uses the derby driver, mysql uses
mysql, but sqlserver can use either jtds or msjdbc (the Microsoft SQL Server
JDBC driver).
If the jtds or msjdbc profile is active, I want to add a database ping (that
is, connect & issue a "select 1") during the initialize phase to ensure that
the intended databases are available over the desired driver.
Vitals:
$ mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600)
Maven home: /Applications/springsource/apache-maven-3.0.4
Java version: 1.6.0_37, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"
I have a parent pom that defines the following in its
project/build/pluginManagement section so that I can ping the database
server(s) that must be alive when the build runs. The SQL command I'm
executing is simply "select 1", and the database
driver/url/username/password are all pretty straightforward. Each execution
differs only by the database driver+url combo & the kind of database ("test"
or "seed"), so there are four permutations.
My intent is to use certain of these executions, activated by Maven
profiles, of course, in various child poms.
===== PARENT POM SNIPPET
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>${app.sql-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${app.jtds.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>sqlserver-jtds-ping-test-db</id>
<goals>
<goal>execute</goal>
</goals>
<phase>initialize</phase>
<configuration>
<driver>${app.rdb.sqlserver-jtds.database.driver.name}</driver>
<username>${app.rdb.sqlserver.test.database.username}</username>
<password>${app.rdb.sqlserver.test.database.password}</password>
<url>${app.rdb.sqlserver-jtds.test.database.url}</url>
<sqlCommand>${app.rdb.sqlserver.ping.sql.command}</sqlCommand>
</configuration>
</execution>
<execution>
<id>sqlserver-jtds-ping-seed-db</id>
<goals>
<goal>execute</goal>
</goals>
<phase>initialize</phase>
<configuration>
<driver>${app.rdb.sqlserver-jtds.database.driver.name}</driver>
<username>${app.rdb.sqlserver.seed.database.username}</username>
<password>${app.rdb.sqlserver.seed.database.password}</password>
<url>${app.rdb.sqlserver-jtds.seed.database.url}</url>
<sqlCommand>${app.rdb.sqlserver.ping.sql.command}</sqlCommand>
</configuration>
</execution>
<execution>
<id>sqlserver-msjdbc-ping-test-db</id>
<goals>
<goal>execute</goal>
</goals>
<phase>initialize</phase>
<configuration>
<driver>${app.rdb.sqlserver-msjdbc.database.driver.name}</driver>
<username>${app.rdb.sqlserver.test.database.username}</username>
<password>${app.rdb.sqlserver.test.database.password}</password>
<url>${app.rdb.sqlserver-msjdbc.test.database.url}</url>
<sqlCommand>${app.rdb.sqlserver.ping.sql.command}</sqlCommand>
</configuration>
</execution>
<execution>
<id>sqlserver-msjdbc-ping-seed-db</id>
<goals>
<goal>execute</goal>
</goals>
<phase>initialize</phase>
<configuration>
<driver>${app.rdb.sqlserver-msjdbc.database.driver.name}</driver>
<username>${app.rdb.sqlserver.seed.database.username}</username>
<password>${app.rdb.sqlserver.seed.database.password}</password>
<url>${app.rdb.sqlserver-msjdbc.seed.database.url}</url>
<sqlCommand>${app.rdb.sqlserver.ping.sql.command}</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
===== PARENT POM SNIPPET
So far, so good. In a child pom, I have the following profiles, defined in
its project/profiles section.
===== CHILD POM SNIPPET
<profile>
<id>jtds</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<executions>
<execution>
<id>sqlserver-jtds-ping-test-db</id>
</execution>
<execution>
<id>sqlserver-jtds-ping-seed-db</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>msjdbc</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<executions>
<execution>
<id>sqlserver-msjdbc-ping-test-db</id>
</execution>
<execution>
<id>sqlserver-msjdbc-ping-seed-db</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
===== CHILD POM SNIPPET
My intent is that I only execute particular executions if the respective
profile is active. The thing is, **all** of the executions are being
executed, regardless of which profile ("jtds" or "msjdbc") is active. So,
if I issue the command "mvn clean initialize -P sqlserver,jtds,...", all of
the executions (sqlserver-jtds-ping-test-db, sqlserver-jtds-ping-seed-db,
sqlserver-msjdbc-ping-test-db, sqlserver-msjdbc-ping-seed-db) are executed.
Why?
How do I achieve my intent? I certainly don't want to copy/paste the
executions from the parent pom into all of the child poms; I want to reuse
these executions in various child poms.
Here is the output of one of my child project builds, reflecting the error.
Notice the first two db pings work correctly; I don't want the second two to
execute, because I'm using the jtds driver to hit sqlserver, and I've yet to
implement msjdbc.
$ mvn clean initialize -P sqlserver,jtds,datanucleus
[INFO] Scanning for projects...
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building Application Domain Model 0.1.0.BUILD-SNAPSHOT
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ app-domain ---
[INFO] Deleting /Users/matthew/Documents/xxx/domain/target
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (sqlserver-jtds-ping-test-db) @
app-domain ---
[INFO] Executing commands
[INFO] 1 of 1 SQL statements executed successfully
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (sqlserver-jtds-ping-seed-db) @
app-domain ---
[INFO] Executing commands
[INFO] 1 of 1 SQL statements executed successfully
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (sqlserver-msjdbc-ping-test-db) @
app-domain ---
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 0.677s
[INFO] Finished at: Thu Feb 07 16:51:30 CST 2013
[INFO] Final Memory: 4M/81M
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.codehaus.mojo:sql-maven-plugin:1.5:execute
(sqlserver-msjdbc-ping-test-db) on project app-domain: Driver class not
found: TODO.com.microsoft.sqlserver.jdbc.Driver -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please
read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
--
View this message in context:
http://maven.40175.n5.nabble.com/Problem-reusing-specific-plugin-executions-with-profiles-tp5746276.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]