简体   繁体   English

从父POM进行mvn安装不会在孙子模块上创建目标文件夹

[英]mvn install from parent POM does not create target folder on grandchild module

The maven project has the following structure Parent POM -> Child POM -> GrandChild POM added below. maven项目具有以下结构,以下添加了“父POM”->“子POM”->“ GrandChild” POM。

When I run mvn clean install from GrandChild POM target folder is generated on the same path as GrandChild POM(parent/child/target) and all jar files from Module1, Module2 and Module3 are populated under this directory. 当我运行mvn clean install从GrandChild POM的目标文件夹会在与GrandChild POM(父/子/目标)相同的路径上生成,并且来自Module1,Module2和Module3的所有jar文件都填充在此目录下。

When I run mvn package from Parent POM target folder is created in parent directory and all the jars are placed within this folder as above. 当我从父目录运行mvn package ,将在父目录中创建目标文件夹,并且所有jar都如上所述放置在该文件夹中。

However if I run mvn clean install from Parent POM, no target folder or jars are generated within the project. 但是,如果我从Parent POM运行mvn clean install ,则项目内不会生成目标文件夹或jar。 Instead all the jars are uploaded to local .m2 repository. 而是将所有jar都上传到本地.m2存储库。

I need jars files to be generated within target folder inside the project(possibly within the grand child directory: parent/child/target), when I run mvn clean install from Parent POM. 当我从父POM运行mvn clean install时,我需要在项目内的目标文件夹(可能在大子目录:parent / child / target)内生成jar文件。 How can I achieve this? 我该如何实现?

Parent POM: 父POM:

<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>parentGroup</groupId>
  <artifactId>parentArtifact</artifactId>
  <version>3.3</version>
  <packaging>pom</packaging>

  <modules>
    <module>ChildModule</module>
  </modules>
</project>

Child POM: 子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>childGroup</groupId>
  <artifactId>childArtifact</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <name>A Camel Spring Route</name>
  <url>http://www.myorganization.org</url>

  <modules>
    <module>GrandChildModule</module>
  </modules>
</project>

GrandChild POM: 孙子POM:

<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>grandChildGroup</groupId>
  <artifactId>grandChildArtifact</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>

  <parent>
    <artifactId>childArtifact</artifactId>
    <groupId>childGroup</groupId>
    <version>1.0.0</version>
    <relativePath>..</relativePath>
  </parent>

  <modules>
    <module>Module1</module>
    <module>Module2</module>
    <module>Module3</module>
  </modules>
</project>

Your child does not have a parent, it should be: 您的孩子没有父母,应该是:

<?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>

  <parent>
    <groupId>parentGroup</groupId>
    <artifactId>parentArtifact</artifactId>
    <version>3.3</version>
  </parent>

  <artifactId>childArtifact</artifactId>
  <packaging>pom</packaging>

  <name>A Camel Spring Route</name>
  <url>http://www.myorganization.org</url>

  <modules>
    <module>GrandChildModule</module>
  </modules>
</project>

You should also let the each sub module take it's version and group from the parent, do not enter <groupId> and <version> if you have <parent> 您还应该让每个子模块从父级获取其版本和组,如果您具有<parent> ,则不要输入<groupId><version> <parent>

Here is a full example working for me: 这是为我工作的完整示例:

Parent 父母

<?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>com.greg</groupId>
  <artifactId>parent-example</artifactId>
  <version>1.0-SNAPSHOT</version>

  <packaging>pom</packaging>

  <name>parent-example</name>

  <modules>
    <module>child-pom</module>
  </modules>

</project>

Child 儿童

<?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>
    <artifactId>parent-example</artifactId>
    <groupId>com.greg</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>child-pom</artifactId>
  <packaging>pom</packaging>

  <name>child-pom</name>

  <modules>
    <module>grandchild-jar</module>
  </modules>

</project>

Grandchild 孙子

<?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>
    <artifactId>child-pom</artifactId>
    <groupId>com.greg</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>grandchild-jar</artifactId>

  <name>grandchild-jar</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

</project>

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

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