获取子模块中父POM中定义的属性[多模块项目]

mon*_*ksy 23 properties maven multi-module

我遇到了将属性从多模块项目的超级pom传递到子pom的问题.

目前我有以下文件: superpom

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>...</groupId>
    <artifactId>meta-all</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <properties>
        <databasedriver>net.sourceforge.jtds.jdbc.Driver</databasedriver>
    </properties>
    <modules>
        <module>child1</module> 
    </modules>
</project>
Run Code Online (Sandbox Code Playgroud)

孩子pom

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>...</groupId>
    <artifactId>child1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
                <version>1.5</version>
                <!-- JDBC Driver -->
                <dependencies>
                    <dependency>
                        <groupId>net.sourceforge.jtds</groupId>
                        <artifactId>jtds</artifactId>
                        <version>1.3.1</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <driver>${project.parent.databasedriver}</driver>
                  ...
                    <autocommit>true</autocommit>
                    <delimiter>GO</delimiter>
                    <delimiterType>row</delimiterType>
                </configuration>
                <executions>
Run Code Online (Sandbox Code Playgroud)

但是,我不知道为什么我无法获取插件配置来检索超级pom的属性.

Fre*_*ose 20

您应该尝试${databasedriver}直接在您的孩子pom中使用.

  • 仅当子 pom 将另一个 pom 作为父级时,这才有效。属性被继承,但不会传递给子模块。 (7认同)
  • 当我使用这种类型的变量时,我在 Maven 构建开始时收到一些警告,指出属性可能是未知的或某种类型的。有没有办法避免或者我必须忽略这些警告?谢谢 (2认同)
  • 对于什么样的属性,你有那个警告?是这个问题吗:http://stackoverflow.com/questions/1981151/warning-on-using-project-parent-version-as-the-version-of-a-module-in-maven-3? (2认同)