Hello,
I have a multi-module project, and each time it runs, I want to insert a row
into a database for only one of the artifacts.
Using the sql maven plugin, I can accomplish this quite nicely when the
project is not multi-module. However, with multi-module projects, a row gets
inserted for every module that is built.
Does anyone know of a way to only have the sql-plugin run once in a
multi-module project?
My setup:
Bamboo 2.5, Nexus 1.4.1, and Maven 2.2.1
64-bit CentOS 2.6.18-164.6.1.el5xen, SVN 1.6.6.
Thanks in advance
Code:
MVN COMMAND:
mvn clean deploy sql:execute -DbuildNumber=${bamboo.buildNumber}
-DbuildKey=${bamboo.buildKey} -Dsvn.rev=${bamboo.custom.svn.revision.number}
POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gid</groupId>
<artifactId>gid-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Name</name>
<description>
My Description.
</description>
<url>http://www.mysite.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.version>3.0.2.RELEASE</spring.version>
<slf4j.version>1.5.10</slf4j.version>
<spring-version>3.0.2.RELEASE</spring-version>
</properties>
<organization>
<name>My-Org</name>
<url>http://www.mysite.com</url>
</organization>
<inceptionYear>2010</inceptionYear>
<modules>
<module>mod-A</module>
<module>mod-B</module>
<module>mod-C</module>
<module>mod-D</module>
<module>mod-E</module>
<module>mod-F</module>
</modules>
<dependencies>
...
[deps listed here]
...
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>${basedir}/src</sourceDirectory>
<testSourceDirectory>${basedir}/test</testSourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
<plugins>
<!-- Compiling with java 1.6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<!-- The following force compilation with full warnings.
-->
<!--
<fork>true</fork>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArguments><Xlint/></compilerArguments>
-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<show>private</show>
</configuration>
</plugin>
<plugin>
<inherited>false</inherited>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>create-sql</id>
<phase>package</phase>
<configuration>
<tasks>
<delete failonerror="false">
<fileset dir="${basedir}">
<include name="*.sql" />
</fileset>
</delete>
<echo file="${buildKey}-${buildNumber}.sql">
INSERT INTO info ( key ) VALUES ( "value" );
</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<dependencies>
<dependency>
<artifactId>mysql-connector-java</artifactId>
<groupId>mysql</groupId>
<version>5.0.5</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://build-db:3306/builds</url>
<username>user</username>
<password>pass</password>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>${buildKey}-${buildNumber}.sql</srcFile>
</srcFiles>
</configuration>
<executions>
<execution>
<phase>process-test-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://nexus-repo/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://nexus-repo/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
RESULT:
The query "select * from builds.info where key='value'" returns 6 results.
EXPECTED RESULT:
I want the query to return only one result.
NOTES:
There are many "workarounds" for this, including changing the SQL query to
include SELECT DISTINCT. However, my point here is to learn how to be able
to execute a goal only once within a multi-module project. It's my hope that
someone knows!
--
View this message in context:
http://old.nabble.com/Execute-SQL-Maven-Plugin-only-once-with-Multi-module-project-tp28748802p28748802.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]