【问题标题】:Getting the properties defined in the parent POM inside the child modules [multi-module projects]获取子模块[多模块项目]中父POM中定义的属性
【发布时间】:2013-10-17 10:18:06
【问题描述】:

我在将属性从 [多模块项目的] 超级 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>

孩子的 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>

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

【问题讨论】:

  • 你试过在你的孩子 pom 中使用 ${databasedriver} 吗?

标签: maven properties multi-module


【解决方案1】:

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

【讨论】:

  • 当我使用这种类型的变量时,我在 maven 的构建开始时收到了一些警告,说属性可能是未知的或类似的。有没有办法避免或者我只需要忽略这些警告?谢谢
  • 对于什么样的属性你有那个警告?是这个问题吗:stackoverflow.com/questions/1981151/…
  • 这仅在子 pom 有另一个作为父级时才有效。属性是继承的,但不会传递给子模块。
  • 为每个子模块重新评估属性。这意味着,例如,如果您将属性设置为相对于父级的路径,它将在子模块路径中重新评估。例如,假设您在父 pom 中设置了以下属性:${basedir}/。如果您在子项中引用 something.path 属性,它将使用以下值重新评估:父/子模块/。
  • 开箱即用,Maven 不允许您在子模块内部使用父模块中定义的自定义属性。时期。要启用它,您必须使用 Maven 的“CI 友好版本”(3.5.0-beta-1 或更高版本)并且您还必须在父母的 pom 中包含 Flatten Maven 插件。尽管各种 Maven 版本存在细微差别,结合各种 IDE 和版本,如果不满足我提到的两个标准,上述 cmets 都不正确。
猜你喜欢
  • 2014-10-19
  • 1970-01-01
  • 2021-02-27
  • 2012-02-06
  • 2013-02-23
  • 1970-01-01
  • 2014-03-28
  • 2021-02-25
  • 1970-01-01
相关资源
最近更新 更多