[英]Change working directory for Maven failsafe pre-integration-test to find Spring configuration
We have a multi module Maven project with multiple executable projects inside. 我们有一个包含多个可执行项目的多模块Maven项目。
The directory structure looks similar to this: 目录结构类似于以下内容:
parent
+- module1
+-- src/main/resources/application.yml
+-- config/bootstrap.yml
+-- config/application-dev.yml
+-- config/application-prod.yml
+-- pom.xml
+- pom.xml
where application.yml
are packaged default values that are not environment specific and all files in the config
folder belongs to external configuration needed only for local development which is not part of the WAR file. 其中
application.yml
是打包的默认值,这些默认值不是特定于环境的,并且config
文件夹中的所有文件都属于仅本地开发所需的外部配置,而不是WAR文件的一部分。
Now if I start the application or tests from the IDE it works as expected. 现在,如果我从IDE启动应用程序或测试,它将按预期工作。 Also, if I run Maven builds in
module1
folder. 另外,如果我运行Maven,则在
module1
文件夹中构建。 However, if I try to build the parent project, the bootstrap.yml
is not found which fails the build during the pre-integration-test
phase. 但是,如果我尝试构建父项目,则找不到
bootstrap.yml
,它会在pre-integration-test
阶段使构建失败。
I discovered that the working directory is set to the parent folder instead of module1
which seems to be the problem as Spring looks in .
我发现工作目录设置为父文件夹而不是
module1
,这似乎是Spring module1
的问题.
and ./config
. 和
./config
。 If I duplicate the config folder to root, it works in all cases. 如果我将config文件夹复制到root,则在所有情况下都可以使用。
Is there any way to tell Maven failsafe to set the working directory to the module folder during pre-integration-test
phase where the Spring Context looks for the configuration? 有什么方法可以告诉Maven故障安全在Spring Context寻找配置的
pre-integration-test
阶段将工作目录设置为module文件夹吗?
parent/pom.xml
: parent/pom.xml
:
<project ...>
<properties>
<maven.version>3.0.0</maven.version>
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>2.20.1</maven-failsafe-plugin.version>
</properties>
<modules>
<module>module1</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*IntTest.java</include>
</includes>
<skipTests>${skipTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
parent/module1/pom.xml
: parent/module1/pom.xml
:
<project>
<parent>
...
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</plugins>
</build>
</project>
Ok, for some reason both <environmentVariables>
and <systemProperties>
in the <config>
block of maven-failsafe-plugin
does not work in combination with spring-boot-maven-plugin
. 好的,由于某些原因,
maven-failsafe-plugin
的<config>
块中的<environmentVariables>
和<systemProperties>
不能与spring-boot-maven-plugin
结合使用。
It appears that spring-boot plugin is responsible to create the (forked) JVM in the pre-integration-test
phase because of this snippet: 似乎由于以下代码片段,spring-boot插件负责在
pre-integration-test
阶段创建(派生的)JVM:
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
I solved it by configuring the spring-boot-maven-plugin
instead: 我通过配置
spring-boot-maven-plugin
解决了它:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<workingDirectory>${basedir}</workingDirectory>
According to documentation ${basedir}
should be the default but maybe it doesn't work with Maven multi-module projects. 根据文档,
${basedir}
应该是默认值,但可能不适用于Maven多模块项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.