I set up sql-maven-plugin like this:
 
<build>
                                <plugins>
                                        <plugin>
                                                
<groupId>org.codehaus.mojo</groupId>
                                                
<artifactId>sql-maven-plugin</artifactId>
                                                
<version>1.5</version>
                                                <dependencies>
                                                        <dependency>
                                                                
<groupId>mysql</groupId>
                                                                
<artifactId>mysql-connector-java</artifactId>
                                                                
<version>${mysql.version}</version>
                                                        </dependency>
                                                </dependencies>
                                                <configuration>
                                                        
<driver>com.mysql.jdbc.Driver</driver>
                                                        
<url>jdbc:mysql://localhost:3306/test</url>
                                                        
<username>scott</username>
                                                        
<password>tiger</password>
                                                </configuration>
                                                <executions>
                                                        <execution>
                                                                
<id>drop-table</id>
                                                                
<phase>process-test-resources</phase>
                                                                <goals>
                                                                        
<goal>execute</goal>
                                                                </goals>
                                                                
<configuration>
                                                                        
<autocommit>true</autocommit>
                                                                        
<srcFiles>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/drop-bonus-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/drop-salgrade-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/drop-dept-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/drop-emp-table.sql</srcFile>
                                                                        
</srcFiles>
                                                                        
<onError>continue</onError>
                                                                
</configuration>
                                                        </execution>
                                                        <execution>
                                                                
<id>create-table</id>
                                                                
<phase>process-test-resources</phase>
                                                                <goals>
                                                                        
<goal>execute</goal>
                                                                </goals>
                                                                
<configuration>
                                                                        
<autocommit>true</autocommit>
                                                                        
<srcFiles>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/create-bonus-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/create-salgrade-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/create-dept-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/ddl/create-emp-table.sql</srcFile>
                                                                        
</srcFiles>
                                                                        
<onError>continue</onError>
                                                                
</configuration>
                                                        </execution>
                                                        <execution>
                                                                
<id>insert-data</id>
                                                                
<phase>process-test-resources</phase>
                                                                <goals>
                                                                        
<goal>execute</goal>
                                                                </goals>
                                                                
<configuration>
                                                                        
<autocommit>true</autocommit>
                                                                        
<srcFiles>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/dml/insert-bonus-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/dml/insert-salgrade-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/dml/insert-dept-table.sql</srcFile>
                                                                                
<srcFile>${basedir}/src/test/sql/mysql/example/dml/insert-emp-table.sql</srcFile>
                                                                        
</srcFiles>
                                                                        
<onError>continue</onError>
                                                                
</configuration>
                                                        </execution>
                                                </executions>
                                        </plugin>
                                </plugins>
                        </build>
 
 
When I execute 'mvn test', sql executed like this:
 
[INFO] --- sql-maven-plugin:1.5:execute (drop-table) @ pte-webapp-prototype ---
[INFO] Executing file: 
C:\Users\bomber\AppData\Local\Temp\drop-bonus-table.1339142444sql
[INFO] Executing file: 
C:\Users\bomber\AppData\Local\Temp\drop-salgrade-table.182961079sql
[INFO] Executing file: 
C:\Users\bomber\AppData\Local\Temp\drop-dept-table.1442040038sql
[ERROR] Failed to execute:  ALTER TABLE DEPT DROP PRIMARY KEY
[ERROR] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can't DROP 
'PRIMARY'; check that column/key exists
[INFO] Executing file: 
C:\Users\bomber\AppData\Local\Temp\drop-emp-table.1792844234sql
[ERROR] Failed to execute:  ALTER TABLE EMP DROP FOREIGN KEY FK_DEPTNO
[ERROR] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can't DROP 
'FK_DEPTNO'; check that column/key exists
[ERROR] Failed to execute:
 ALTER TABLE EMP DROP PRIMARY KEY
[ERROR] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can't DROP 
'PRIMARY'; check that column/key exists
[ERROR] Failed to execute:
 DROP INDEX PK_EMP ON EMP
[ERROR] com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can't DROP 
'PK_EMP'; check that column/key exists
[INFO] 5 of 9 SQL statements executed successfully
.....
 
 
But when I execute 'mvn sql:execute', sql does not work at all:
 
[INFO] ------------------------------------------------------------------------
[INFO] Building pte-webapp-prototype Maven Webapp 1.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (default-cli) @ pte-webapp-prototype ---
[INFO] 0 of 0 SQL statements executed successfully
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.598 s
 
 
 
Why 'mvn test' is ok but 'mvn sql:execute' is not?
Which part of my configuration is wrong?
 
 

Reply via email to