从包含多个可选模块的 Maven 项目构建任意发行版

发布于 2024-08-17 13:17:55 字数 1301 浏览 8 评论 0原文

首先:我的 Maven 知识有限,所以请耐心等待。 ;-) 我有一个简单的 Maven 项目,当前由三个模块组成。包含应用程序核心的模块称为 core(创意名称,嗯?:-)),其他模块基本上都是该核心模块的插件。有一个限制:核心模块中只能添加一个插件。

核心模块有自己的 Spring IoC 配置,减去插件配置。这非常简单:核心代码将读取一个名为“plugin”的 bean,该 bean 未在核心配置中定义。插件模块将提供自己的配置文件,该文件将提供一个名为“plugin”的 bean,然后由核心代码使用。这非常适合我的用例。

我想提供将部署系统的管理员,一种构建包含核心、选定的插件和合理的默认配置的发行版的简单方法。也许是 tar.gz 或类似的东西。我不想让他挖掘我的 Spring IoC 文件,将它们复制在一起等等。像 TCP/IP 端口这样的实际配置是在属性文件中完成的。

为了澄清我的意思,我构建了一个示例结构。请注意,文件名仅用于说明目的。

/bin/core.jar [Build from core module]  
/bin/plugin.jar [Build from a plugin module]

/lib-bin/library-required-by-plugin.jar [Dependency resolved by maven + copy]
/lib-bin/library-required-by-core.jar [Dependency resolved by maven + copy]
/lib-bin/another-library-required-by-core.jar [Dependency resolved by maven + copy]

/etc/spring/core-beans.xml [Copied from core module /etc/]
/etc/spring/plugin.xml [Copied from plugin module /etc/]
/etc/default-core-config.properties [Copied from core module /etc/]
/etc/default-plugin-config.properties [Copied from plugin module /etc/]

我目前正在摆弄组装插件,但我似乎在兜圈子,没有任何效果。相当令人沮丧。如果您需要更多信息或不明白我的观点,请随时询问。 :-)

另外澄清我的问题:如何做到这一点? (嗯,就这么简单:-))正如我之前所说,我对 Maven 的了解是有限的,目前我一无所获,即使我知道程序集插件可能是可行的方法。特别是如何从每个模块获取依赖项,在哪里配置插件(在父项目中?),甚至一点程序集描述符都会有很大帮助。

感谢您的所有意见!

first of all: my Maven knowledge is limited so please bear with me. ;-) I have a simple Maven Project currently consisting of three modules. The module containing the core of the application is called core (Creative name, huh? :-)) and the other modules are basically plugins for this core module. There is one restriction: Only one plugin can be added to the core module.

The core module has its own Spring IoC configuration minus the plugin configuration. This is quite simple: The core code will read a bean named "plugin" which is not defined in the core configuration. The plugin modules will ship their own configuration files which will supply a bean named "plugin" which is then used by the core code. This fits perfectly in my use-case.

I want to provide the Admin, which will deploy the system, a simple way to build a distribution containing the core, a selected plugin and a reasonable default configuration. Maybe a tar.gz or something like that. I don't want him to dig though my Spring IoC files, copy them together, etc. etc. The actual configuration like TCP/IP ports are done in property files.

To clarify what i mean I've build an example structure. Note that the filenames are for explanation purposes only.

/bin/core.jar [Build from core module]  
/bin/plugin.jar [Build from a plugin module]

/lib-bin/library-required-by-plugin.jar [Dependency resolved by maven + copy]
/lib-bin/library-required-by-core.jar [Dependency resolved by maven + copy]
/lib-bin/another-library-required-by-core.jar [Dependency resolved by maven + copy]

/etc/spring/core-beans.xml [Copied from core module /etc/]
/etc/spring/plugin.xml [Copied from plugin module /etc/]
/etc/default-core-config.properties [Copied from core module /etc/]
/etc/default-plugin-config.properties [Copied from plugin module /etc/]

I currently mess around with the assembly plugin but i seem to go round in circles and nothing works. Pretty frustrating. If you need any more information or do not get my point feel free to ask. :-)

Addition to clarify my question: How to do that? (Well, its just that simple :-)) As I stated before, my knowledge of Maven is limited and currently i'm getting nowhere, even if I know that the assembly plugin might be the way to go. Especially how to get the dependencies from each module, where to configure the plugin (In the parent project?) and even a bit of an assembly descriptor would help a lot.

Thank you for all your input!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2024-08-24 13:17:55

我使用程序集插件来打包命令行应用程序的发行版,如下所示:

<前><代码><插件>;
maven- assembly-plugin;
<版本>2.2-beta-3
<配置>
<描述符>
<描述符>src/main/ assembly/bin.xml


<处决>
<执行>
程序集
<阶段>封装
<目标>
<目标>组装



  • 定义程序集描述符,即指定可分发存档的内容和结构,下面是我的:

<前><代码><汇编>;
bin
false;
<格式>
<格式>zip

<文件集>
<文件集>
<目录>目标
<包括>
ctmemapi.properties
<包括>ctmxml/*
<包括>scampa
<包含>*.bat
<包含>*.sh

${project.artifactId}-${project.version}
<文件模式>755

<文件集>
<目录>目标
<包括>
<包含>scampa*.jar

${project.artifactId}-${project.version}/lib
<文件模式>644

<文件集>
<目录>src/test/data
${project.artifactId}-${project.version}/test-data
<文件模式>644


<依赖集>
<依赖集>
${project.artifactId}-${project.version}/lib
<文件模式>644


  • 使用以下任一命令创建程序集

    <块引用>

    mvn 程序集:程序集
    mvn包
    mvn安装
    mvn部署

I used the assembly plugin to package a distribution of a command line application as follows:

  • Define assembly plugin in pom,
    this includes binding the plugin to the package phase of the build life-cycle
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-3</version>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/bin.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>assembly</id>
            <phase>package</phase>
            <goals>
                <goal>assembly</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • Define the assembly descriptor, i.e. specify the contents and structure of your distributable archive, here's mine below:
<assembly>
  <id>bin</id>
  <includeBaseDirectory>false</includeBaseDirectory>
  <formats>
      <format>zip</format>
  </formats>
  <fileSets>
      <fileSet>
          <directory>target</directory>
          <includes>
              <include>ctmemapi.properties</include>
              <include>ctmxml/*</include>
              <include>scampa</include>
              <include>*.bat</include>
              <include>*.sh</include>
          </includes>
          <outputDirectory>${project.artifactId}-${project.version}</outputDirectory>
          <fileMode>755</fileMode>
      </fileSet>
      <fileSet>
          <directory>target</directory>
          <includes>
              <include>scampa*.jar</include>
          </includes>
          <outputDirectory>${project.artifactId}-${project.version}/lib</outputDirectory>
          <fileMode>644</fileMode>
      </fileSet>
      <fileSet>
          <directory>src/test/data</directory>
          <outputDirectory>${project.artifactId}-${project.version}/test-data</outputDirectory>
          <fileMode>644</fileMode>
      </fileSet>
  </fileSets>
  <dependencySets>
      <dependencySet>
          <outputDirectory>${project.artifactId}-${project.version}/lib</outputDirectory>
          <fileMode>644</fileMode>
      </dependencySet>
  </dependencySets>
</assembly>
  • Create the assembly with either of the following commands

    mvn assembly:assembly
    mvn package
    mvn install
    mvn deploy

虐人心 2024-08-24 13:17:55

如果您只是期待确认,那么我确认您所描述的情况是 Maven 程序集插件。我只是使用单独的配置文件来处理限制(“只能将一个插件添加到核心模块”)。

如果您需要更具体的指导,请添加具体问题:)

If you are just expecting a confirmation, then I confirm that the situation you have described is a perfect use case for the Maven Assembly plugin. I'd just use separate profiles to deal with the restriction ("Only one plugin can be added to the core module").

If you are expecting more specific guidance, please add a specific question :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文