简体   繁体   English

更改Maven故障安全预集成测试的工作目录以查找Spring配置

[英]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.

相关问题 在集成前测试期间运行maven-clean-plugin而不清理默认目标目录 - Running maven-clean-plugin during pre-integration-test without cleaning default target directory Jetty不在集成前测试阶段(Maven)开始 - Jetty doesn't start in pre-integration-test phase (Maven) 在Eclipse中运行需要Maven预集成测试执行的JUnit集成测试? - Running JUnit integration tests in Eclipse that need Maven pre-integration-test executions? 无法在预集成测试阶段启动Jetty - Not able to start Jetty in pre-integration-test phase 是否有类似于Integration-Test的集成前和集成后测试的类名称约定 - Is there any class name conventions for pre-integration-test and post-integration-test similar to integration-test Maven Failsafe插件:如何使用集成前和集成后测试阶段 - Maven Failsafe Plugin: how to use the pre- and post-integration-test phases Maven集成测试不适用于Spring - Maven integration test not working with Spring Maven故障安全插件未触发集成测试 - Maven failsafe plugin not firing integration test Maven-failsafe-plugin:skipTests配置不适用于Spring Boot 1.4集成测试 - Maven-failsafe-plugin: skipTests configuration does not work for Spring Boot 1.4 integration tests 如何通过 maven-failsafe-plugin 运行基于 spring-boot 的应用程序的集成测试? - How to run integration test of a spring-boot based application through maven-failsafe-plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM