java - Maven integration-test doesn't find my class in same package structure -
here files:
pom parent:
<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>my.group</groupid> <artifactid>my.artifact.pom</artifactid> <version>1.0-snapshot</version> <packaging>pom</packaging> <modules> <module>my.artifact.ws</module> </modules> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.4.2.release</version> </parent> <properties> <!-- test --> <maven.test.failure.ignore>false</maven.test.failure.ignore> </properties> //lot of dependencies... <!-- profiles --> <profiles> <profile> <id>local</id> <activation> <activebydefault>true</activebydefault> </activation> <unit-tests.skip>false</unit-tests.skip> <integration-tests.skip>true</integration-tests.skip> </properties> </profile> <profile> <id>integration</id> <modules> <module>my-module-integration-test</module> </modules> <properties> <unit-tests.skip>true</unit-tests.skip> <integration-tests.skip>false</integration-tests.skip> </properties> </profile> </profiles> <!-- plugin --> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-resources-plugin</artifactid> <configuration> <encoding>${encoding}</encoding> </configuration> </plugin> </plugins> </build> </project>
module-ws pom:
<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> <artifactid>my.artifact.ws</artifactid> <packaging>jar</packaging> <parent> <groupid>my.group</groupid> <artifactid>my.artifact.pom</artifactid> <version>1.0-snapshot</version> </parent> //lot of dependencies... </project>
integration-test pom:
<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> <artifactid>my.artifact.integration.test</artifactid> <packaging>jar</packaging> <parent> <groupid>my.group</groupid> <artifactid>my.artifact.pom</artifactid> <version>1.0-snapshot</version> </parent> <properties> <unit-tests.skip>false</unit-tests.skip> <integration-tests.skip>true</integration-tests.skip> </properties> <dependencies> <dependency> <groupid>my.group</groupid> <artifactid>my.artifact.ws</artifactid> <version>1.0-snapshot</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactid>maven-surefire-plugin</artifactid> </plugin> <plugin> <artifactid>maven-failsafe-plugin</artifactid> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
my folder structure:
my-module |-- my-module-integration-test | `-- src | `-- test | `-- java | `-- | `-- module | `-- ws | `-- rest | `-- mytest `-- my-module-ws `-- src `-- main `-- java `-- `-- module `-- application
when run mvn clean install -p integration
receive message:
[error] failed execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testcompile (default-testcompile) on project mp-schedule-integration-test: compilation failure: compilation failure: [error] /users/me/dev/my-module/my-module-integration-test/src/test/java/my/module/ws/rest/mytest.java:[3,28] cannot find symbol [error] symbol: class application [error] location: package my.module
if put application class inside test structure in my-module-integration-test
works (go horse)
could me?
ps.: name os modules , projects wrong hide original names.
-- update after github post
the problem repackaging spring-boot-maven-plugin invoked in pom.xml
of mp-schedule-ws
module. once spring-boot-maven-plugin
has been included in pom.xml automatically attempt rewrite archives make them executable using spring-boot:repackage
goal.
due dependency in mp-integration-test
package, mp-schedule-ws/target/mp-schedule-ws-1.0-snapshot.jar
on classpath, if @ internals see loads org/springframework/boot/loader/*
classes , classes reside in boot-inf
folder, such boot-inf/classes/com/cnova/mpschedule/application.class
.
if put spring-boot-maven-plugin in comment, build works charm.
to solve this, there strategies follow:
- use classifier build seperate jar repackaged executable
- conditionally bind
spring-boot-maven-plugin
build execution specific packaging profile, not executed in integration test profile - create seperate module building spring boot executable jar
- the spring boot plugin keeps backup of original jar .jar.original extension, copy using maven plugin , add classpath [ugly hack]
an example of first strategy adding classifier in pom.xml
of mp-schedule-ws
:
<build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <configuration> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build>
this give 2 jars:
$ ls -al mp-schedule-ws/target/ -rwxr--r-- 1 nick wheel 55188756 nov 23 06:38 mp-schedule-ws-1.0-snapshot-exec.jar -rw-r--r-- 1 nick wheel 20311 nov 23 06:38 mp-schedule-ws-1.0-snapshot.jar
another example of second strategy define specific build profile in mp-schedule-ws
module, such as:
<profiles> <profile> <id>package-application</id> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <configuration> <executable>true</executable> </configuration> </plugin> </plugins> </build> </profile> </profiles>
this gives:
$apache-maven-3.3.9/bin/mvn clean install -p integration [info] mp-schedule ........................................ success [ 0.230 s] [info] mp-schedule-core ................................... success [ 3.845 s] [info] mp-schedule-ws ..................................... success [ 0.563 s] [info] mp-schedule-integration-test ....................... success [ 0.721 s] [info] ------------------------------------------------------------------------ [info] build success [info] ------------------------------------------------------------------------ [info] total time: 5.751 s
and build executable jar spring boot:
$apache-maven-3.3.9/bin/mvn clean install -p package-application [info] mp-schedule ........................................ success [ 0.255 s] [info] mp-schedule-core ................................... success [ 3.822 s] [info] mp-schedule-ws ..................................... success [ 0.968 s] [info] ------------------------------------------------------------------------ [info] build success [info] ------------------------------------------------------------------------ [info] total time: 5.396 s
of course can choose solution strategy fits project best.
-- old answer - obsolete, kept reference
it works here on maven 3.x, thing had change add
<version>1.0-snapshot</version>
to my.artifact.ws
since declared dependency in my.artifact.integration.test
<dependency> <groupid>my.group</groupid> <artifactid>my.artifact.ws</artifactid> <version>1.0-snapshot</version> </dependency>
i added missing <properties>
start tag in local profile.
Comments
Post a Comment