暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Maven 实用技巧

宇宙湾 2019-05-16
1036

Maven 提速

多线程

  1. # 用 4 个线程构建,以及根据 CPU 核数每个核分配 1 个线程进行构建

  2. $ mvn -T 4 clean install

  3. $ mvn -T 1C clean install

复制

跳过测试

  1. -DskipTests # 不执行测试用例,但编译测试用例类生成相应的 class 文件至 target/test-classes 下

  2. -Dmaven.test.skip=true # 不执行测试用例,也不编译测试用例类


  3. # 结合上文的`并行执行`

  4. $ mvn -T 1C clean install -Dmaven.test.skip=true


  5. # 如果还是阻塞: 资源管理器 - shutdown all java app


  6. # 如果 jar 包过大,可以下载按照路径放在 repository 中,之后可能还需要 mvn clean 来下载 groovy-all-2.3.11.pom 文件 (mvnrepository.com)

  7. D:\apps\maven\repository\org\codehaus\groovy\groovy-all\2.3.11\groovy-all-2.3.11.jar

复制

编译失败后,接着编译

  1. # 如果是 Apache Eagle 之类带有几十个子项目的工程,如果从头编译所有的模块,会很耗功夫

  2. # 通过指定之前失败的模块名,可以继续之前的编译

  3. $ mvn -rf :moduleName clean install

复制

跳过失败的模块,编译到最后再报错

  1. $ mvn clean install --fail-at-end

复制

使用 Aliyun 国内镜像

  1. <mirror>

  2. <id>alimaven</id>

  3. <name>aliyun maven</name>

  4. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

  5. <mirrorOf>central</mirrorOf>

  6. </mirror>

复制

指定 Repository 目录

  1. <!-- Default: ~/.m2/repository -->

  2. <localRepository>D:\apps\maven\repository</localRepository>

复制

如何使用 Maven 编译指定 module

  1. $ mvn install -pl <module_name> -am


  2. -pl, --projects (Build specified reactor projects instead of all project)

  3. -am, --also-make (If project list is specified, also build projects required by the list)

  4. -amd, --also-make-dependents (If project list is specified, also build projects that depend on)

复制

Maven 标准目录结构

  1. src/main/java Application/Library sources

  2. src/main/resources Application/Library resources

  3. src/main/filters Resource filter files

  4. src/main/webapp Web application sources

  5. src/test/java Test sources

  6. src/test/resources Test resources

  7. src/test/filters Test resource filter files

  8. src/it Integration Tests (primarily for plugins)

  9. src/assembly Assembly descriptors

  10. src/site Site

  11. LICENSE.txt Project's license

  12. NOTICE.txt Notices and attributions required by libraries that the project depends on

  13. README.txt Project's readme

复制

如何在 Maven 中使用多个 source

  1. <plugin>

  2. <groupId>org.codehaus.mojo</groupId>

  3. <artifactId>build-helper-maven-plugin</artifactId>

  4. <executions>

  5. <execution>

  6. <phase>generate-sources</phase>

  7. <goals>

  8. <goal>add-source</goal>

  9. </goals>

  10. <configuration>

  11. <sources>

  12. <source>src/main/scala</source>

  13. </sources>

  14. </configuration>

  15. </execution>

  16. </executions>

  17. </plugin>

复制

Using Scala UnitTest by Maven

安装 Scala

Maven 依赖

  1. <dependency>

  2. <groupId>org.scalatest</groupId>

  3. <artifactId>scalatest_2.10</artifactId>

  4. <version>2.2.1</version>

  5. </dependency>

复制

创建 unittest 需要的 trait

  1. import org.scalatest._

  2. abstract class UnitTestStyle extends FlatSpec

  3. with Matchers with OptionValues with Inside with Inspectors

复制

编写测试

  1. import spark.streaming.detect.SendNetflow

  2. class SendNetflowTest extends UnitTestStyle {


  3. "Clean method" should "output a string" in {


  4. val s = "0,tcp,http,SF,229,9385,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,9,9,0.00,0.00,0.00,0.00,1.00,0.00,0.00,9,90,1.00,0.00,0.11,0.04,0.00,0.00,0.00,0.00,normal."

  5. SendNetflow.clean(s) should be("0,229,9385,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,9,9,0.00,0.00,0.00,0.00,1.00,0.00,0.00,9,90,1.00,0.00,0.11,0.04,0.00,0.00,0.00,0.00\tnormal.")

  6. }


  7. it should "throw Exception if an empty string is inputted" in {

  8. val emptyS = ""

  9. a[RuntimeException] should be thrownBy {

  10. SendNetflow.clean(emptyS)

  11. }

  12. }

复制

Tips: Full code is here.

Using slf4j by Maven

Maven 配置

  1. <slf4j.version>1.7.12</slf4j.version>

  2. <logback.version>1.1.3</logback.version>


  3. <dependency>

  4. <groupId>ch.qos.logback</groupId>

  5. <artifactId>logback-core</artifactId>

  6. <version>${logback.version}</version>

  7. </dependency>


  8. <dependency>

  9. <groupId>ch.qos.logback</groupId>

  10. <artifactId>logback-classic</artifactId>

  11. <version>${logback.version}</version>

  12. <exclusions>

  13. <exclusion>

  14. <groupId>ch.qos.logback</groupId>

  15. <artifactId>logback-core</artifactId>

  16. </exclusion>

  17. <exclusion>

  18. <groupId>org.slf4j</groupId>

  19. <artifactId>slf4j-api</artifactId>

  20. </exclusion>

  21. </exclusions>

  22. </dependency>


  23. <dependency>

  24. <groupId>org.slf4j</groupId>

  25. <artifactId>slf4j-api</artifactId>

  26. <version>${slf4j.version}</version>

  27. </dependency>


  28. <dependency>

  29. <groupId>org.slf4j</groupId>

  30. <artifactId>jcl-over-slf4j</artifactId>

  31. <version>${slf4j.version}</version>

  32. <exclusions>

  33. <exclusion>

  34. <groupId>org.slf4j</groupId>

  35. <artifactId>slf4j-api</artifactId>

  36. </exclusion>

  37. </exclusions>

  38. </dependency>


  39. <dependency>

  40. <groupId>org.slf4j</groupId>

  41. <artifactId>log4j-over-slf4j</artifactId>

  42. <version>${slf4j.version}</version>

  43. <exclusions>

  44. <exclusion>

  45. <groupId>org.slf4j</groupId>

  46. <artifactId>slf4j-api</artifactId>

  47. </exclusion>

  48. </exclusions>

  49. </dependency>


  50. <dependency>

  51. <groupId>org.slf4j</groupId>

  52. <artifactId>jul-to-slf4j</artifactId>

  53. <version>${slf4j.version}</version>

  54. <exclusions>

  55. <exclusion>

  56. <groupId>org.slf4j</groupId>

  57. <artifactId>slf4j-api</artifactId>

  58. </exclusion>

  59. </exclusions>

  60. </dependency>

复制

logback.xml in resources directory

  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <configuration>

  3. <!-- %p:Level %m:Message %c.%M:Package+Method %F:%L:File+Line -->

  4. <property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} | %p | %m | %c.%M | %F:%L %n"/>


  5. <!-- Print in Console -->

  6. <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

  7. <encoder charset="UTF-8">

  8. <pattern>${pattern}</pattern>

  9. </encoder>

  10. </appender>


  11. <root level="ALL">

  12. <appender-ref ref="STDOUT"/>

  13. </root>

  14. </configuration>

复制

编码

示例
  1. private static final Logger _log = LoggerFactory.getLogger(ZKEventWatch.class);

  2. _log.info(state);

复制
遇到的坑
SLF4J multi bindings
  • 描述

  1. SLF4J: Class path contains multiple SLF4J bindings.

  2. SLF4J: Found binding in [jar:file:/D:/apps/maven/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

  3. SLF4J: Found binding in [jar:file:/D:/apps/maven/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

复制
  • 解决

  1. <!-- 使用 Apache Curator 需要 exclusion slf4j-log4j12,否则会出现问题 -->

  2. <dependency>

  3. <groupId>org.apache.curator</groupId>

  4. <artifactId>curator-recipes</artifactId>

  5. <version>${apache.curator.version}</version>

  6. <exclusions>

  7. <exclusion>

  8. <groupId>org.slf4j</groupId>

  9. <artifactId>slf4j-log4j12</artifactId>

  10. </exclusion>

  11. </exclusions>

  12. </dependency>

复制

Tips: Full code is here.

导出依赖 Jar

 如何利用 Maven 将依赖的 jar 都导入到一个文件夹下

  1. <build>

  2. <plugins>

  3. <plugin>

  4. <groupId>org.apache.maven.plugins</groupId>

  5. <artifactId>maven-dependency-plugin</artifactId>

  6. <version>2.10</version>

  7. <configuration>

  8. <outputDirectory>${project.build.directory}/lib</outputDirectory>

  9. <excludeTransitive>false</excludeTransitive>

  10. <stripVersion>false</stripVersion>

  11. </configuration>

  12. </plugin>

  13. </plugins>

  14. </build>

复制
  1. $ mvn clean dependency:copy-dependencies


  2. # 将 yuzhouwan-flume 依赖的 jars 都 导出到一个文件夹

  3. # 用相对路径,不能是 绝对路径,否则 maven 会报错:Unknown lifecycle phase "Java"

  4. $ mvn dependency:copy-dependencies -f yuzhouwan-flume/pom.xml -DoutputDirectory=yuzhouwan-flume/target/lib

  5. $ mvn dependency:copy-dependencies -f yuzhouwan-api/yuzhouwan-admin-api/pom.xml -DoutputDirectory=target/lib

复制

Profiles

Tips: Full code is here.

日志级别

 -Dorg.slf4j.simpleLogger.defaultLogLevel=error

Generate Code for Antlr

  1. $ mvn clean install -T 1C -DskipTests=true -Dorg.slf4j.simpleLogger.defaultLogLevel=error -B

复制

Maven Properties

  1. $ mvn clean install -Dmy.property=propertyValue

复制

Maven Check Style

  1. $ mvn clean install -Dcheckstyle.skip

复制

Maven Update

  1. $ mvn clean install -U

  2. # -U means force update of dependencies.

复制

Maven Dependency

Pre-download

  1. $ mvn dependency:go-offline

复制

Version-compare

  1. # 在开发一些 Coprocessor 的时候,需要保证和 HBase 集群的依赖 jar 版本一致,可以使用该方法

  2. $ mvn versions:compare-dependencies -DremotePom=org.apache.hbase:hbase:0.98.8-hadoop2 -DreportOutputFile=depDiffs.txt

复制

Maven Proxy

命令行设置

  1. # Linux (bash)

  2. $ export MAVEN_OPTS="-DsocksProxyHost=10.10.10.10 -DsocksProxyPort=8080"

  3. # Windows

  4. $ set MAVEN_OPTS="-DsocksProxyHost=10.10.10.10 -DsocksProxyPort=8080"

复制

配置文件

  1. $ vim $MAVEN_HOME/conf/settings.xml


  2. <proxies>

  3. <!--<proxy>

  4. <id>http-proxy</id>

  5. <active>true</active>

  6. <protocol>http</protocol>

  7. <host>10.10.10.10</host>

  8. <port>8888</port>

  9. <nonProxyHosts>*.yuzhouwan.com</nonProxyHosts>

  10. </proxy>-->


  11. <proxy>

  12. <id>socks-proxy</id>

  13. <active>true</active>

  14. <protocol>socks5</protocol>

  15. <host>127.0.0.1</host>

  16. <port>1080</port>

  17. <nonProxyHosts>*.yuzhouwan.com</nonProxyHosts>

  18. </proxy>

  19. </proxies>

复制

Avro 插件

创建 avsc 文件

  1. {

  2. "namespace": "com.yuzhouwan.hacker.avro",

  3. "type": "record",

  4. "name": "User",

  5. "fields": [

  6. {

  7. "name": "name",

  8. "type": "string"

  9. },

  10. {

  11. "name": "favorite_number",

  12. "type": [

  13. "int",

  14. "null"

  15. ]

  16. },

  17. {

  18. "name": "favorite_color",

  19. "type": [

  20. "string",

  21. "null"

  22. ]

  23. }

  24. ]

  25. }

复制

使用 avro-tools 工具生成 Avro 类

  1. # 下载 avro-tools

  2. # https://mvnrepository.com/artifact/org.apache.avro/avro-tools/1.8.1

  3. # http://archive.apache.org/dist/avro/avro-1.8.1/java/ (better)

  4. $ wget http://archive.apache.org/dist/avro/avro-1.8.1/java/avro-tools-1.8.1.jar -c avro-tools-1.8.1.jar


  5. # 利用 avsc 文件中的 Schema 生成 Avro 类

  6. $ java -jar avro-tools-1.8.1.jar compile schema user.avsc .

复制

使用 avro-plugin 插件生成 Avro 类

  1. <properties>

  2. <apache.avro.version>1.7.7</apache.avro.version>

  3. </properties>


  4. <dependencies>

  5. <!-- apache avro -->

  6. <dependency>

  7. <groupId>org.apache.avro</groupId>

  8. <artifactId>avro</artifactId>

  9. <version>${apache.avro.version}</version>

  10. </dependency>

  11. </dependencies>


  12. <build>

  13. <plugins>

  14. <plugin>

  15. <groupId>org.apache.avro</groupId>

  16. <artifactId>avro-maven-plugin</artifactId>

  17. <version>${apache.avro.version}</version>

  18. <executions>

  19. <execution>

  20. <phase>generate-sources</phase>

  21. <goals>

  22. <goal>schema</goal>

  23. </goals>

  24. <configuration>

  25. <sourceDirectory>${project.basedir}/src/main/resources/avsc/</sourceDirectory>

  26. <outputDirectory>${project.basedir}/src/main/java/</outputDirectory>

  27. </configuration>

  28. </execution>

  29. </executions>

  30. </plugin>

  31. </plugins>

  32. </build>

复制

Tips: Full code is here.

Shade 插件解决 Jar 多版本共存

适用场景

 在整合大型项目时,可能都依赖 commons-collections 此类的工具包,但是也可能 commons-collections 的版本却因为不一致,导致冲突。可以通过 Shade 插件的 relocation
方法进行重定向,此时冲突的依赖 package 名,会被重命名,并且依赖该 jar 的程序,都会被自动替换为新的 package 名

基本用法

实例一
  1. <properties>

  2. <maven.shade.plugin.version>2.4.3</maven.shade.plugin.version>

  3. </properties>

  4. <plugin>

  5. <groupId>org.apache.maven.plugins</groupId>

  6. <artifactId>maven-shade-plugin</artifactId>

  7. <version>2.4.3</version>

  8. <executions>

  9. <execution>

  10. <phase>package</phase>

  11. <goals>

  12. <goal>shade</goal>

  13. </goals>

  14. <configuration>

  15. <shadedArtifactAttached>false</shadedArtifactAttached>

  16. <createSourcesJar>true</createSourcesJar>

  17. <artifactSet>

  18. <excludes>

  19. <exclude>org.mapdb.*</exclude>

  20. </excludes>

  21. </artifactSet>

  22. <relocations>

  23. <relocation>

  24. <pattern>org.apache.commons.collections</pattern>

  25. <shadedPattern>com.yuzhouwan.org.apache.commons.collections</shadedPattern>

  26. </relocation>

  27. </relocations>

  28. </configuration>

  29. </execution>

  30. </executions>

  31. </plugin>

复制
实例二
  1. <plugin>

  2. <groupId>org.apache.maven.plugins</groupId>

  3. <artifactId>maven-shade-plugin</artifactId>

  4. <version>${maven.shade.plugin.version}</version>

  5. <executions>

  6. <execution>

  7. <phase>package</phase>

  8. <goals>

  9. <goal>shade</goal>

  10. </goals>

  11. <configuration>

  12. <shadedArtifactAttached>true</shadedArtifactAttached>

  13. <shadedClassifierName>all</shadedClassifierName>

  14. <createSourcesJar>true</createSourcesJar>

  15. <artifactSet>

  16. <!-- 因为 org.glassfish 里面存在类似 public static class Builder implements javax.ws.rs.client.Invocation.Builder 全限定名的写法 -->

  17. <!-- 所以只能用 shade 去隐藏 com.sun.jersey -->

  18. <excludes>

  19. <exclude>org.glassfish.*</exclude>

  20. </excludes>

  21. </artifactSet>

  22. <relocations>

  23. <relocation>

  24. <pattern>javax.ws</pattern>

  25. <shadedPattern>shade.javax.ws</shadedPattern>

  26. </relocation>

  27. <relocation>

  28. <pattern>org.apache.curator</pattern>

  29. <shadedPattern>shade.org.apache.curator</shadedPattern>

  30. </relocation>

  31. <!--<relocation>

  32. <pattern>org.glassfish</pattern>

  33. <shadedPattern>shade.org.glassfish</shadedPattern>

  34. </relocation>

  35. <relocation>

  36. <pattern>com.sun.jersey</pattern>

  37. <shadedPattern>shade.com.sun.jersey</shadedPattern>

  38. </relocation>-->

  39. </relocations>

  40. </configuration>

  41. </execution>

  42. </executions>

  43. </plugin>

复制

踩过的坑

Error creating shaded jar: Error in ASM processing class
描述
  1. Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project base-k2d-flow: Error creating shaded jar: Error in ASM processing class com/yuzhouwan/bigdata/k2d/K2DPartitioner.class: 52264 -> [Help 1]

复制
解决

 升级 maven-shade-plugin
版本到 2.4.x

通过 Shade 将问题解决后,部署上线后,依赖冲突复现
解决

 因为官方明确指出 java.io.File.listFiles()
方法返回的文件序列顺序,是不做保证的。所以,上线后运行环境发生变化,加载 lib
目录下的 jar
顺序,可能会发生变化。这时候,就需要利用不同 lib
目录,并修改 classpath 的方式,将 jar
加载顺序确定下来

 例如,在整合 Druid 这类依赖树比较庞大的工程,就遇到了这么一种情况。Druid 中 com.sun.jersey (1.19) 和 Dataflow 中 org.glassfish.jersey (2.25.1) 发生冲突。增加了上述实例二中的 Shade 操作仍然会在线上环境,复现依赖冲突。这时,我们可以通过增加一个 lib_jersey
目录,存放 javax.ws.rs-api-2.1.jar
,并修改 classpath 为 lib_jersey/*:lib/*
。以此,保证了 lib_jersey
中的依赖得以优先加载,从而解决冲突

Assembly 插件

不同模块的依赖,打包到不同的目录下

具体步骤

 第一步,先在负责打包分发的 distribution 模块中,设置 pom.xml 文件

  1. <properties>

  2. <maven.assembly.plugin.version>2.3</maven.assembly.plugin.version>

  3. </properties>


  4. <packaging>pom</packaging>


  5. <dependencies>

  6. <dependency>

  7. <groupId>com.yuzhouwan</groupId>

  8. <artifactId>core</artifactId>

  9. </dependency>

  10. <dependency>

  11. <groupId>com.yuzhouwan</groupId>

  12. <artifactId>ai</artifactId>

  13. </dependency>

  14. <dependency>

  15. <groupId>com.yuzhouwan</groupId>

  16. <artifactId>bigdata</artifactId>

  17. </dependency>

  18. </dependencies>


  19. <build>

  20. <plugins>

  21. <plugin>

  22. <artifactId>maven-assembly-plugin</artifactId>

  23. <version>${maven.assembly.plugin.version}</version>

  24. <executions>

  25. <execution>

  26. <id>assemble</id>

  27. <phase>package</phase>

  28. <goals>

  29. <goal>single</goal>

  30. </goals>

  31. <configuration>

  32. <descriptors>

  33. <descriptor>src/assembly/bin.xml</descriptor>

  34. <descriptor>src/assembly/src.xml</descriptor>

  35. </descriptors>

  36. <tarLongFileMode>gnu</tarLongFileMode>

  37. </configuration>

  38. </execution>

  39. </executions>

  40. </plugin>

  41. </plugins>

  42. </build>

复制

 第二步,创建好对应的 bin.xml 和 src.xml

  1. <assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  2. xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"

  3. xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">


  4. <id>bin</id>


  5. <formats>

  6. <format>dir</format>

  7. <format>tar.gz</format>

  8. </formats>


  9. <baseDirectory>yuzhouwan-${project.version}-bin</baseDirectory>


  10. <fileSets>

  11. <fileSet>

  12. <directory>../</directory>


  13. <excludes>

  14. <exclude>**/target/**</exclude>

  15. <exclude>**/.classpath</exclude>

  16. <exclude>**/.project</exclude>

  17. <exclude>**/.settings/**</exclude>

  18. <exclude>lib/**</exclude>

  19. <exclude>conf/**</exclude>

  20. </excludes>


  21. <includes>

  22. <include>README</include>

  23. <include>LICENSE</include>

  24. <include>NOTICE</include>

  25. <include>CHANGELOG</include>

  26. <include>RELEASE-NOTES</include>

  27. <include>conf/</include>

  28. </includes>

  29. </fileSet>


  30. <fileSet>

  31. <directory>../</directory>

  32. <includes>

  33. <include>bin/yuzhouwan-cli.sh</include>

  34. </includes>

  35. <fileMode>0777</fileMode>

  36. <directoryMode>0755</directoryMode>

  37. </fileSet>

  38. </fileSets>


  39. <moduleSets>

  40. <moduleSet>

  41. <includeSubModules>false</includeSubModules>

  42. <useAllReactorProjects>true</useAllReactorProjects>

  43. <includes>

  44. <include>com.yuzhouwan:yuzhouwan-core</include>

  45. </includes>

  46. <excludes>

  47. <exclude>com.yuzhouwan:ai</exclude>

  48. <exclude>com.yuzhouwan:bigdata</exclude>

  49. </excludes>

  50. <binaries>

  51. <outputDirectory>lib/core</outputDirectory>

  52. <unpack>false</unpack>

  53. <dependencySets>

  54. <dependencySet>

  55. <useProjectArtifact>false</useProjectArtifact>

  56. <useTransitiveDependencies>true</useTransitiveDependencies>

  57. <unpack>false</unpack>

  58. <excludes>

  59. <exclude>com.yuzhouwan:ai</exclude>

  60. <exclude>com.yuzhouwan:bigdata</exclude>

  61. </excludes>

  62. </dependencySet>

  63. </dependencySets>

  64. </binaries>

  65. </moduleSet>


  66. <moduleSet>

  67. <includeSubModules>false</includeSubModules>

  68. <useAllReactorProjects>true</useAllReactorProjects>

  69. <includes>

  70. <include>com.yuzhouwan:ai</include>

  71. </includes>

  72. <excludes>

  73. <exclude>com.yuzhouwan:bigdata</exclude>

  74. </excludes>

  75. <binaries>

  76. <outputDirectory>lib/plugins/ai</outputDirectory>

  77. <unpack>false</unpack>

  78. <dependencySets>

  79. <dependencySet>

  80. <useProjectArtifact>false</useProjectArtifact>

  81. <useTransitiveDependencies>true</useTransitiveDependencies>

  82. <unpack>false</unpack>

  83. <excludes>

  84. <exclude>com.yuzhouwan:bigdata</exclude>

  85. </excludes>

  86. </dependencySet>

  87. </dependencySets>

  88. </binaries>

  89. </moduleSet>


  90. <moduleSet>

  91. <includeSubModules>false</includeSubModules>

  92. <useAllReactorProjects>true</useAllReactorProjects>

  93. <includes>

  94. <include>com.yuzhouwan:bigdata</include>

  95. </includes>

  96. <excludes>

  97. <exclude>com.yuzhouwan:ai</exclude>

  98. </excludes>

  99. <binaries>

  100. <outputDirectory>lib/plugins/bigdata</outputDirectory>

  101. <unpack>false</unpack>

  102. <dependencySets>

  103. <dependencySet>

  104. <useProjectArtifact>false</useProjectArtifact>

  105. <useTransitiveDependencies>true</useTransitiveDependencies>

  106. <unpack>false</unpack>

  107. <excludes>

  108. <exclude>com.yuzhouwan:ai</exclude>

  109. </excludes>

  110. </dependencySet>

  111. </dependencySets>

  112. </binaries>

  113. </moduleSet>

  114. </moduleSets>

  115. </assembly>

复制
  1. <assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  2. xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"

  3. xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">


  4. <id>src</id>


  5. <formats>

  6. <format>dir</format>

  7. <format>tar.gz</format>

  8. </formats>


  9. <baseDirectory>yuzhouwan-${project.version}-src</baseDirectory>


  10. <fileSets>

  11. <fileSet>

  12. <directory>../</directory>


  13. <excludes>

  14. <exclude>**/target/**</exclude>

  15. <exclude>**/.classpath</exclude>

  16. <exclude>**/.project</exclude>

  17. <exclude>**/*.iml</exclude>

  18. <exclude>**/.settings/**</exclude>

  19. <exclude>lib/**</exclude>

  20. </excludes>


  21. <includes>

  22. <include>.ci</include>

  23. <include>.gitignore</include>

  24. <include>DEVNOTES</include>

  25. <include>README</include>

  26. <include>LICENSE</include>

  27. <include>NOTICE</include>

  28. <include>CHANGELOG</include>

  29. <include>RELEASE-NOTES</include>

  30. <include>bin/**</include>

  31. <include>conf/**</include>

  32. <include>native/**</include>

  33. <include>pom.xml</include>

  34. <include>dev-conf/**</include>

  35. <include>yuzhouwan-core/**</include>

  36. <include>yuzhouwan-ai/**</include>

  37. <include>yuzhouwan-bigdata/**</include>

  38. </includes>

  39. </fileSet>

  40. </fileSets>

  41. </assembly>

复制

 构建完成之后,即可看到 yuzhouwan-ai
yuzhouwan-bigdata
模块的依赖,分别被打包到了 plugins/ai
plugins/bigdata
目录下

  1. # 需要预先安装 tree 命令(yum install tree -y)

  2. $ tree

  3. .

  4. ├── bin

  5.    └── yuzhouwan-cli.sh

  6. └── lib

  7. ├── core

  8. └── plugins

  9. ├── ai

  10. └── bigdata

复制
踩过的坑
模块间存在版本冲突的 jar 包
  • 问题描述

  1. Currently, inclusion of module dependencies may produce unpredictable results if a version conflict occurs

复制

  • 解决

    如果上述 yuzhouwan-ai
    yuzhouwan-bigdata
    模块,与 yuzhouwan-common
    模块存在版本冲突的 jar 包,则需要将 bin.xml
    拆解成 bin-common.xml
    bin-ai.xml
    bin-bigdata.xml
    三个 assembly 配置文件,依次进行构建(此时需要将 id 设置成一样的,不然会被构建到不同的目录下)。否则,版本冲突的 jar 包,将只能保留其中一个版本,且具体保留哪个版本是不确定的



文章转载自宇宙湾,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论