【问题标题】:Maven Assembly plugin - Include repo jarsMaven Assembly 插件 - 包括 repo jars
【发布时间】:2010-12-29 17:09:33
【问题描述】:

我有一个多模块项目,我正在使用程序集插件来构建一个 tar 文件。我已使用 moduleSets 标记将我的所有模块包含在程序集插件中。

<moduleSets>
    <moduleSet>
         <includes>
             <include>module1</include>
             <include>module2</include>

我所有的模块 jar 都组装到一个 lib 文件夹中。我想将本地 maven 存储库中的 mysql jar 添加到包含我所有其他模块的同一个 lib 文件夹中。在模块集中添加本地存储库 jar 似乎不起作用。

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'mysql.mysql-connector-java:mysql-connector-java-version'

如何包含来自 maven 存储库的 jar。

【问题讨论】:

    标签: maven-2


    【解决方案1】:

    我认为您需要在dependencySet 的includes 子元素中声明您的mysql jar。

    类似这样的:

    <assembly>
      <id>my-assembly</id>
      ...    
      <dependencySets>
        <dependencySet>
          <outputDirectory>/lib</outputDirectory>
          <includes>
            <include>mysql:mysql-connector-java</include>
          </includes>
          <unpack>false</unpack>
          <scope>runtime</scope>
        </dependencySet>
      </dependencySets>
      ...
    </assembly>
    

    有关此元素的更多详细信息,请参阅 Maven 手册的 Descriptor Format 文档和/或章节 12.5.4. dependencySets Section。

    【讨论】:

    • +1。另一个不错的选择是将此 mysql 连接器添加到需要它作为运行时依赖项的模块。
    【解决方案2】:

    我认为你不需要做任何特别的事情,只要确保 mysql 在你的项目中被列为依赖项并且它应该可以工作。同样适用于模块的依赖项 - 只需将它们列为依赖项。下面是汇编插件的典型配置。

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,通过改变 pom 依赖的范围来编译来解决它。

          <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <scope>compile</scope>
          </dependency>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-04
        • 1970-01-01
        • 2018-12-20
        • 2013-06-15
        • 1970-01-01
        • 1970-01-01
        • 2019-01-31
        • 2016-04-01
        相关资源
        最近更新 更多