가 어떻게 내 메이븐 pom.xml
및/또는 sql-maven-plugin
구성 할 수 있습니다 의존에서 SQL-받는다는 - 플러그인 실행을 실행 내 프로젝트 com.example.project
의 pom.xml
을 구축 하시겠습니까? 현재 com.example.project
에 대해 pom.xml
에 mvn clean install
을 실행하면 SQL 데이터베이스에 lib.example.jdbc
에 생성 된 테이블이있는 것을 알 수 있습니다. 한 가지 확실한 해결 방법은 각 pom.xml
파일에서 mysql.database
에 대해 다른 속성을 사용하는 것이지만 큰 문제는 라이브러리의 (종속성) db 실행이 주 프로젝트의 테스트 단계에서 실행되고 있다는 것입니다. 하나는 수 백개의 pom.xml
종속성과 자신의 테스트 및 최종 프로젝트를 빌드 할 때 실행해서는 안된 db 실행을 가질 수 있기 때문에 이것이 올바른지 상상할 수 없습니다.Maven 프로젝트는 내 의존성, <code>lib.example.jdbc</code>에서 지정한 단위 테스트 관련 DB의 실행이 때 실행되지 않도록
업데이트 : 스프링 애노테이션이 내 답변에서 발견 된 범인 이었으므로이를 반영하도록 질문 태그를 업데이트했습니다. 여기
이 pom.xml
lib.example.jdbc
의에서 관련 샘플입니다 :
...
<groupId>lib.example</groupId>
<artifactId>jdbc</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
...
<properties>
...
<mysql.port>3306</mysql.port>
<mysql.database>testDb</mysql.database>
<mysql.user>root</mysql.user>
<mysql.pass>password</mysql.pass>
</properties>
...
<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>5.1.44</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${mysql.host}:${mysql.port}/${mysql.database}?useSSL=false</url>
<username>${mysql.user}</username>
<password>${mysql.pass}</password>
<settingsKey>sensibleKey</settingsKey>
<!--all executions are ignored if -Dmaven.test.skip=true-->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>create-db</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:mysql://${mysql.host}:${mysql.port}?useSSL=false</url>
<autocommit>true</autocommit>
<sqlCommand>create database if not exists `${mysql.database}`</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
그리고 여기에 관련된 pom.xml
com.example.project
의에서 샘플입니다 : 추가 조사 후
<groupId>com.example</groupId>
<artifactId>project</artifactId>
<version>0.0.1</version>
...
<properties>
...
<mysql.port>3306</mysql.port>
<mysql.database>testDb</mysql.database>
<mysql.user>root</mysql.user>
<mysql.pass>password</mysql.pass>
</properties>
...
<dependencies>
...
<dependency>
<groupId>lib.example</groupId>
<artifactId>jdbc</artifactId>
<version>1.0.0</version>
</dependency>
...
</dependencies>
...
<build>
<finalName>${project.artifactId}</finalName>
<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>5.1.44</version>
</dependency>
</dependencies>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${mysql.host}:${mysql.port}?useSSL=false</url>
<username>${mysql.user}</username>
<password>${mysql.pass}</password>
<settingsKey>sensibleKey</settingsKey>
<!--all executions are ignored if -Dmaven.test.skip=true-->
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>drop-db-before-test-if-any</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:mysql://${mysql.host}:${mysql.port}?useSSL=false</url>
<autocommit>true</autocommit>
<sqlCommand>drop database if exists `${mysql.database}`</sqlCommand>
<sqlCommand>create database `${mysql.database}`</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
내 SQL 데이터베이스는 당신이 실제로 라이브러리 프로젝트에서 목표를 실행하는'com.example.project' 빌드입니다 확신 lib.example.jdbc의 *에서 만든 테이블이 찾을 *? 이상하게 보입니다. 우리가 확실히 말할 수있는 문제가 발생하는 전체'com.example.project' 빌드 로그를 제공하십시오 (필요한 경우 의미있는 요소를 모호하게 만듭니다) –
@ 피에르 B. 문제가되는 SQL은'com.example.project'에 대한 테스트를 실행할 때 확실히 실행되고 있습니다. 왜냐하면 DB를 제거하고 테스트를 다시 실행했기 때문에 문제가있는 SQL은 다시 보았습니다. 그러나 Maven 플러그인은 그 원인이 아닙니다. 설명을 위해 내 대답을보십시오. – nofunatall