Java 具有settings.xml属性的子模块的变量依赖关系

Java 具有settings.xml属性的子模块的变量依赖关系,java,xml,maven,pom.xml,Java,Xml,Maven,Pom.xml,我有一个具有以下结构的示例maven项目: parent frontend backend 前端依赖于后端。 后端具有用于测试的数据库驱动程序依赖项。但是,此依赖关系应取决于developers settings.xml <dependency> <groupId>${database.driver.groupId}</groupId> <artifactId>${database.driver

我有一个具有以下结构的示例maven项目:

parent
   frontend
   backend
前端依赖于后端。 后端具有用于测试的数据库驱动程序依赖项。但是,此依赖关系应取决于developers settings.xml

    <dependency>
        <groupId>${database.driver.groupId}</groupId>
        <artifactId>${database.driver.artifactId}</artifactId>
        <version>${database.driver.version}</version>
        <scope>test</scope>
    </dependency>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <profiles>
        <profile>
            <id>database</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <database.driver.groupId>mysql</database.driver.groupId>
                <database.driver.artifactId>mysql-connector-java</database.driver.artifactId>
                <database.driver.version>5.1.9</database.driver.version>
            </properties>
        </profile>
    </profiles>
</settings>
有趣的是,如果我将概要文件声明移动到父级的pom.xml中,它就可以正常工作了

所以我的问题是,为什么子模块的属性来自settings.xml时没有被替换

注: “help:active profiles-N”显示settings.xml中的配置文件处于活动状态

注2:Maven版本附带STS,嵌入了3.0.4


遵循settins.xml和poms 后端

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>de.phil.mvntest</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>backend</artifactId>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>${database.driver.groupId}</groupId>
            <artifactId>${database.driver.artifactId}</artifactId>
            <version>${database.driver.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

4.0.0
德菲尔·姆文泰斯特
父母亲
0.0.1-快照
后端
UTF-8
朱尼特
朱尼特
3.8.1
编译
${database.driver.groupId}
${database.driver.artifactId}
${database.driver.version}
测试
方端

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>de.phil.mvntest</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>frontend</artifactId>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.phil.mvntest</groupId>
            <artifactId>backend</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

4.0.0
德菲尔·姆文泰斯特
父母亲
0.0.1-快照
前端
UTF-8
德菲尔·姆文泰斯特
后端
0.0.1-快照
编译
母公司

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.phil.mvntest</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>backend</module>
        <module>frontend</module>
    </modules>
</project>

4.0.0
德菲尔·姆文泰斯特
父母亲
0.0.1-快照
聚甲醛
UTF-8
后端
前端
settings.xml

    <dependency>
        <groupId>${database.driver.groupId}</groupId>
        <artifactId>${database.driver.artifactId}</artifactId>
        <version>${database.driver.version}</version>
        <scope>test</scope>
    </dependency>
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <profiles>
        <profile>
            <id>database</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <database.driver.groupId>mysql</database.driver.groupId>
                <database.driver.artifactId>mysql-connector-java</database.driver.artifactId>
                <database.driver.version>5.1.9</database.driver.version>
            </properties>
        </profile>
    </profiles>
</settings>

数据库
真的
mysql
mysql连接器java
5.1.9

操纵配置文件中的依赖项不是很安全。它工作得相当好的唯一情况是针对不同的依赖项运行测试,甚至使用maven invoker插件更安全。部署的pom只能有一个依赖项集