繁体   English   中英

Maven不解析父pom.xml文件中的属性

[英]Maven does not resolve properties from parent pom.xml file

我有一个父项目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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.sss.it.cf</groupId>
            <artifactId>cf-tenant-prov</artifactId>
            <version>3.3.0-SNAPSHOT</version>
        </parent>
        <groupId>com.sss.it.cf</groupId>
        <artifactId>cf-tenant-prov.parent</artifactId>
        <version>3.3.0-SNAPSHOT</version>
        <packaging>pom</packaging>
    <properties>
        <liquibase.version>3.1.1</liquibase.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <postgresql.version>42.2.5</postgresql.version>
        <spring.security.jwt.version>1.0.9.RELEASE</spring.security.jwt.version>
        <spring.security.oauth2.version>2.0.15.RELEASE</spring.security.oauth2.version>
        <iaik.iaik_jce.version>5.22</iaik.iaik_jce.version>
    </properties>

    <modules>
        <module>cf-tenant-prov.initdb</module>
        <module>cf-tenant-prov.router</module>
        <module>cf-tenant-prov.common</module>
        <module>cf-tenant-prov.integration</module>
        <module>cf-tenant-prov.dao</module>
        <module>cf-tenant-prov.messaging</module>
        <module>cf-tenant-prov.service</module>
        <module>cf-tenant-prov.web</module>
        <module>cf-tenant-prov.assembly</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.1.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-api-mockito2</artifactId>
                <version>${powermock-api-mockito2.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.powermock</groupId>
                <artifactId>powermock-module-junit4</artifactId>
                <version>${powermock-module-junit4.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

这个项目中的模块有这样的poms:

    <?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">
    <parent>
        <artifactId>cf-tenant-prov.parent</artifactId>
        <groupId>com.sss.it.cf</groupId>
        <version>3.2.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cf-tenant-prov.common</artifactId>
    <dependencies>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>


        <dependency>
            <groupId>iaik</groupId>
            <artifactId>iaik_jce</artifactId>
            <version>${iaik.iaik_jce.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
      </dependencies>
    </project>

这在我的机器上成功构建,但是在jenkins构建中,如果有人克隆了这个git并进行了maven构建,我会收到如下错误:

[ERROR] [ERROR] Some problems were encountered while processing the POMs:

[ERROR] 'dependencies.dependency.version' for iaik:iaik_jce:jar must be a valid version but is '${iaik.iaik_jce.version}'. @ com.sap.it.cf:cf-tenant-prov.common:
[unknown-version], C:\Users\I501807\git\hcisvcprov\cf-tenant-prov.parent\cf-tenant-prov.common\pom.xml 
<file:///C:/Users/XXXXXX/git/hcisvcprov/cf-tenant-prov.parent/cf-tenant-prov.common/pom.xml> , line 33, column 22 

对于所有版本。

当这些属性在单个poms中时,这工作得更早。

我只是将这些依赖项向上移动了一级,以便它们不会在每个pom文件中重复。

你的父母说它是版本3.3.0-SNAPSHOT 但是你的模块指的是版本3.2.0-SNAPSHOT 这些属性是否已包含在3.2.0-SNAPSHOT中,或者您是否忘记增加模块POM中的版本?

您的父pom.xml应具有所有依赖项(将在子模块中使用的每个依赖项)

<dependencyManagement>
  .
  .
</dependencyManagement>

包括它们的版本(您可以使用属性或直接指定版本),然后您可以在任何子模块中使用这些依赖项,甚至不指定版本。

父pom.xml应如下所示: -

<?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>
  <parent>
    <groupId>com.sss.it.cf</groupId>
    <artifactId>cf-tenant-prov</artifactId>
    <version>3.3.0-SNAPSHOT</version>
  </parent>
  <groupId>com.sss.it.cf</groupId>
  <artifactId>cf-tenant-prov.parent</artifactId>
  <version>3.3.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <properties>
    <liquibase.version>3.1.1</liquibase.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <postgresql.version>42.2.5</postgresql.version>
    <spring.security.jwt.version>1.0.9.RELEASE</spring.security.jwt.version>
    <spring.security.oauth2.version>2.0.15.RELEASE</spring.security.oauth2.version>
    <iaik.iaik_jce.version>5.22</iaik.iaik_jce.version>
  </properties>

  <modules>
    <module>cf-tenant-prov.initdb</module>
    <module>cf-tenant-prov.router</module>
    <module>cf-tenant-prov.common</module>
    <module>cf-tenant-prov.integration</module>
    <module>cf-tenant-prov.dao</module>
    <module>cf-tenant-prov.messaging</module>
    <module>cf-tenant-prov.service</module>
    <module>cf-tenant-prov.web</module>
    <module>cf-tenant-prov.assembly</module>
  </modules>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.1.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito2</artifactId>
        <version>${powermock-api-mockito2.version}</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>${powermock-module-junit4.version}</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
      </dependency>
      <dependency>
        <groupId>iaik</groupId>
        <artifactId>iaik_jce</artifactId>
        <version>${iaik.iaik_jce.version}</version>
      </dependency>
      <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

和儿童模块应如下所示: -

<?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">
  <parent>
    <artifactId>cf-tenant-prov.parent</artifactId>
    <groupId>com.sss.it.cf</groupId>
    <version>3.3.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>cf-tenant-prov.common</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
    </dependency>
    <dependency>
      <groupId>iaik</groupId>
      <artifactId>iaik_jce</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </dependency>
  </dependencies>
</project>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM