更改应用Maven Spring Boot和War插件的顺序。

huangapple 未分类评论46阅读模式
英文:

Changing order of applying maven spring-boot and war plugins

问题

我正在使用 spring-boot-maven-plugin 将 Spring Boot 添加到我的应用程序中,还使用 >maven-war-plugin 将生成的 .war 文件移动到目标(本地文件系统)位置。

不幸的是,当我将它们都添加到 pom.xml 中时:

<plugins>
	<plugin>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-maven-plugin</artifactId>
	</plugin>

	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-war-plugin</artifactId>
		<version>3.2.1</version>
		<configuration>
			<outputDirectory>C:/Location</outputDirectory>
		</configuration>
	</plugin>
</plugins>

发生的情况是首先生成 .war 文件,然后将其移动到 C:/Location,随后项目构建中 /target 中原始的 .war 文件被 spring-boot-maven-plugin 更新(可以通过控制台输出和 .war 文件在 /target 内部的更大文件大小来确认)。

因此,最终我得到的是位于错误位置的正确 .war 文件,以及位于正确位置的错误(在添加 Spring Boot 之前的) .war 文件。

是否有一种方法可以使这些步骤以相反的顺序发生?首先应用 Spring Boot,然后将结果移动到 C:/Location

我尝试过通过在 spring boot 的 <plugin> 中添加:

<executions>
	<execution>
		<phase>package</phase>
	</execution>
</executions>

以及在 war 插件中添加:

<executions>
	<execution>
		<phase>install</phase>
	</execution>
</executions>

但似乎没有任何效果(spring boot 在 war 插件之后被应用):

[INFO] --- maven-war-plugin:3.2.1:war (default-war) @ app ---
[INFO] Packaging webapp
[INFO] Assembling webapp [app] in [G:\app\target\app-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [G:\app\src\main\webapp]
[INFO] Webapp assembled in [310 msecs]
[INFO] Building war: C:\Location\app-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:repackage (repackage) @ app ---
[INFO] Replacing main artifact with repackaged archive
英文:

I am using spring-boot-maven-plugin to add spring boot to my application and also &gt;maven-war-plugin to move the generated .war to target (local filesystem) destination.

Unfortunatelly, when I add both of them into pom.xml:

&lt;plugins&gt;
	&lt;plugin&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
	&lt;/plugin&gt;

	&lt;plugin&gt;
		&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
		&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
		&lt;version&gt;3.2.1&lt;/version&gt;
		&lt;configuration&gt;
			&lt;outputDirectory&gt;C:/Location&lt;/outputDirectory&gt;
		&lt;/configuration&gt;
	&lt;/plugin&gt;
&lt;/plugins&gt;

What happens is that first the .war is generated. Than moved to C:/Location. And later the original .war in /target of my project build is getting updated with spring-boot-maven-plugin (it can be confirmed both by console output and greater file size of .war inside /target.

So I end up with correct .war in inccorect location and incorrect .war (before adding spring boot) in correct location.

Is there a way to make those steps happen in reverse order? To first apply spring boot and later move the result to C:/Location?

I've tried by adding:

&lt;executions&gt;
	&lt;execution&gt;
		&lt;phase&gt;package&lt;/phase&gt;
	&lt;/execution&gt;
&lt;/executions&gt;

to &lt;plugin&gt; for spring boot and:

&lt;executions&gt;
	&lt;execution&gt;
		&lt;phase&gt;install&lt;/phase&gt;
	&lt;/execution&gt;
&lt;/executions&gt;

for war plugin, but it seems to take no effect whatsoever (spring boot is applied after war plugin):

[INFO] --- maven-war-plugin:3.2.1:war (default-war) @ app ---
[INFO] Packaging webapp
[INFO] Assembling webapp [app] in [G:\app\target\app-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [G:\app\src\main\webapp]
[INFO] Webapp assembled in [310 msecs]
[INFO] Building war: C:\Location\app-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.2.4.RELEASE:repackage (repackage) @ app ---
[INFO] Replacing main artifact with repackaged archive

huangapple
  • 本文由 发表于 2020年5月30日 02:33:42
  • 转载请务必保留本文链接:https://java.coder-hub.com/62092565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定