代码之家  ›  专栏  ›  技术社区  ›  Никита Михайлов

只导入用maven构建的库的一个概要文件

  •  3
  • Никита Михайлов  · 技术社区  · 8 年前

    我的pom.xml中有两个配置文件一个默认值和另一个用于构建扩展客户端库我在另一个maven项目中导入这个库。问题是它使用了第一个项目中的所有依赖项,甚至是默认概要文件中提到的依赖项解决这个问题的最好办法是什么在生成jar时,是否可以在pom文件中只放置一个概要文件还是可以在导入依赖项时选择配置文件?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Essex Boy    8 年前

    你需要这样的东西

    (1)一个将一切结合在一起的父母

    <?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>hm-parent</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>pom</packaging>
    
      <name>hm-parent</name>
    
      <modules>
        <module>hm-client</module>
        <module>hm-default</module>
      </modules>
    
    </project>
    

    2)客户端模块

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com.greg</groupId>
        <artifactId>hm-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>hm-client</artifactId>
      <name>hm-client</name>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    
    </project>
    

    3)一个默认模块,它从同一个项目的同一个父项目中拉入客户端

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
    
      <parent>
        <groupId>com.greg</groupId>
        <artifactId>hm-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
    
      <artifactId>hm-default</artifactId>
      <name>hm-default</name>
    
      <dependencies>
        <dependency>
          <groupId>com.greg</groupId>
          <artifactId>hm-client</artifactId>
          <version>${project.version}</version>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    
    </project>