栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

父Pom和微服务

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

父Pom和微服务

多模块父pom的“问题”是,没有复杂的配置文件,它将模块锁定在相同的发布周期中(假设您使用的是Release
Plugin
)。

我使用Maven的方式是让一个父pom声明:

  • 常见的依赖关系(日志API,JUnit等)。
  • 常用插件。
  • dependencyManagement
    节中的所有依赖项。
  • pluginManagement
    节中的所有插件。

每个模块都会将父pom作为其父代,但父代对模块一无所知。

这样做的好处来自上面的最后两个项目符号,即“管理”部分。“管理”部分中包含的所有内容都需要在要使用特定依赖项或插件的模块中重新声明。

例如,父母可能看起来像这样:

<project>  <groupId>com.example</groupId>  <artifactId>parent</artifactId>  <version>1.0.00-SNAPSHOT</version>  ...  <dependencies>    <dependency>      <groupId>org.slf4j</groupId>      <artifactId>slf4j-api</artifactId>      <version>1.7.7</version>    </dependency>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>4.11</version>      <scope>test</scope>    </dependency>  </dependencies>  <dependencyManagement>    <dependency>      <groupId>commons-lang</groupId>      <artifactId>commons-lang</artifactId>      <version>2.6</version>    </dependency>    <dependency>      <groupId>commons-collections</groupId>      <artifactId>commons-collections</artifactId>      <version>2.1</version>    </dependency>  </dependencyManagement>  <plugins>    <plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-compiler-plugin</artifactId>      <version>3.1</version>      <configuration>        <source>1.8</source>        <target>1.8</target>      </configuration>    </plugin>  <plugins>  <pluginManagement>    <plugins>      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-assembly-plugin</artifactId>        <version>2.4</version>        <configuration>          <appendAssemblyId>false</appendAssemblyId>          <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor>          </descriptors>        </configuration>        <executions>          <execution> <id>make-assembly</id> <phase>package</phase> <goals>   <goal>single</goal> </goals>          </execution>        </executions>      </plugin>    </plugins>  </pluginManagement></project>

模块可能看起来像这样:

<project>  <parent>    <groupId>com.example</groupId>    <artifactId>parent</artifactId>    <version>1.0.00-SNAPSHOT</version>  </parent>  <groupId>com.example</groupId>  <artifactId>module</artifactId>  <version>1.0.00-SNAPSHOT</version>  <dependencies>    <dependency>      <groupId>commons-lang</groupId>      <artifactId>commons-lang</artifactId>   </dependency>  </dependencies>  <plugins>    <plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-assembly-plugin</artifactId>    </plugin>  </plugins></project>

该模块将:

  • 有依赖性
    org.slf4j:slf4j-api:1.7.7:compile
    junit:junit:4.11:test
    commons-lang:commons-lang:2.6:compile
  • 有插件
    org.apache.maven.plugins:maven-assembly-plugin:2.4


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号