美文网首页
Maven多模块打包问题

Maven多模块打包问题

作者: aix91 | 来源:发表于2019-03-08 08:18 被阅读0次

1. 项目结构

tdk
├── tdk-server
├── tdk-api
├── tdk-inf
└── tdk-client

tdk pom

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>tdk</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>
    <modules>
        <module>tdk-api</module>
        <module>tdk-client</module>
        <module>tdk-inf</module>
        <module>tdk-server</module>
    </modules>

tdk-inf pom

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>tdk</artifactId>
        <version>0.0.1</version>
    </parent>
    <packaging>jar</packaging>
    <version>0.0.1</version>
    <artifactId>tdk-inf</artifactId>

tdk-server 依赖tdk-inf

        <dependency>
            <groupId>com.ximalaya.webgroup</groupId>
            <artifactId>tdk-inf</artifactId>
        </dependency>

2. 打包问题

tdk-server依赖tdk-inf,如果要打包tdk-server,则需要将tdk-inf发布到仓库。在depoly tdk-inf到仓库后,由于它依赖tdk pom,如果tdk pom没有deploy到仓库,就会导致tdk-server的打包失败。

3. 解决办法

  • 在tdk的pom下执行deploy,这样就会自动将tdk 以及所有的子module都发布到仓库。
  • 去掉子模块,将每个模块作为一个独立的项目发布

4. 操作方法

  • 在tdk pom里面添加 distributionManagement
  <distributionManagement>
    <repository>
      <id>nexus</id>
      <name>Releases</name>
      <url>http://xxxx/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
      <id>nexus</id>
      <name>Snapshot</name>
      <url>http://xxxx/repository/maven-snapshots</url>
    </snapshotRepository>
  </distributionManagement>
  • 在parent pom下执行deploy
  • 如果不想让某些子模块部署到仓库,可以在子模块中添加
<properties>
    <maven.deploy.skip>true</maven.deploy.skip>
</properties>

相关文章

网友评论

      本文标题:Maven多模块打包问题

      本文链接:https://www.haomeiwen.com/subject/tkjhpqtx.html