gpt4 book ai didi

java - 使用 Maven 发布不同的配置

转载 作者:行者123 更新时间:2023-11-29 06:19:09 27 4
gpt4 key购买 nike

我目前正在将我们的构建过程从 Ant 迁移到 Maven。我们的应用程序部署到许多不同的客户,每个客户都有一组独特的依赖项和配置。我可以实现不同的配置文件来对这些进行建模并从中构建所需的 war 。然而,这是一个在编译时发生的过程。

每个版本都标记在 SVN 下,并上传到我们的内部 Nexus 存储库。我希望能够获取定义的版本并根据配置文件重建它。有没有办法做这样的事情?我应该使用配置文件以外的其他东西吗?

最佳答案

"declare several execution for the war plugin to produce several artifacts (and install/deploy them)" This sounds like this might be the way forward. How would I go about doing this?

这有点违背 Maven 黄金法则(每个模块规则一个主要工件),但可以做到。 One artifact with multiple configurations in Maven博客文章描述了一种实现这种方法的方法:

I decided to put all the environment specific configuration in a special source tree, with the following structure:

+-src/
+-env/
+-dev/
+-test/
+-prod/

Then I configured the maven-war-plugin to have three different executions (the default plus two extra), one for each environment, producing three different war files: beer-1.0-dev.war, beer-1.0-test.war and beer-1.0-prod.war. Each of these configurations used the standard output files from the project and then copied the content from the corresponding src/env/ directory on to the output files, enabling an override file to be placed in the corresponding src/env/ directory. It also supported copying a full tree structure into the output directory. Thus if you for instance wanted to replace the web.xml in test you simply created the following directory:

src/env/test/WEB-INF/

and placed your test specific web.xml in this directory and if you wanted to override a db.property file placed in the classpath root directory for the test environment you created the following directory:

src/env/test/WEB-INF/classes

and placed your test specific db.property file in this directory.

I kept the src/main directory configured for development environment. The reason for this was to be able to use the maven-jetty-plugin without any extra configuration. Configuration

Below you find the maven-war-plugin configuration that I used to accomplish this:

<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<classifier>prod</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory>
<webResources>
<resource>
<directory>src/env/prod</directory>
</resource>
</webResources>
</configuration>
<executions>
<execution>
<id>package-test</id>
<phase>package</phase>
<configuration>
<classifier>test</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-test</webappDirectory>
<webResources>
<resource>
<directory>src/env/test</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory>
<webResources>
<resource>
<directory>src/env/dev</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>

(...) I can define each customer project with profiles but I don't know if there's a way to release them to a repository.

您有多种选择:

  • 使用配置文件并多次运行构建(使用分类器创建工件并安装/部署它们)
  • 声明 war 插件的多个执行以生成多个工件(并安装/部署它们)
  • 使用不同的模块(也许 war overlays 将公共(public)部分与特定部分合并)

Or at least a way in Maven to automatically build an artifact with a specified profile from say an SVN tag.

好吧,这是可行的。但如果没有关于特定问题的更多详细信息,就很难做到更精确。

关于java - 使用 Maven 发布不同的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3866784/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com