我开始赶上spring-boot-maven-plugin.It中重新打包目标的功能,看起来很有希望,但我需要对其进行一些微调。
我可以通过在我的项目中的某个地方创建一个layers.xml文件轻松地做到这一点,但问题是我不只有一个项目,而是六个项目。所有的项目都需要相同类型的分层,但我并不是真的想为我想要使用的每个项目复制相同的配置。
例如,一个好看的解决方案是将该配置文件提取到一个单独的jar中,并让插件从那里获取配置文件,但我认为没有办法做到这一点。有没有其他解决方案不需要我将配置文件复制到我拥有的每个项目中?
不幸的是,即使我的项目使用相同的父项目,但不在同一多模块项目中。
发布于 2020-08-07 20:04:29
我设法想出了一个解决方案。
在问这个问题之前,我的spring-boot-mave-plugin配置如下所示:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<phase>package</phase>
<configuration>
<layers>
<enabled>true</enabled>
<configuration><!-- something like classpath:layers.xml --></configuration>
</layers>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>artifact</groupId>
<artifactId>with-layers.xml</artifactId>
<version>...</version>
</dependency>
</dependencies>
</plugin>通过引入maven-dependency-plugin,解决方案变得更加复杂,它下载前面提到的依赖项,并使用以下配置将其解压缩到build文件夹中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-shc-build-tools</id>
<goals>
<goal>unpack</goal>
</goals>
<phase>package</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>artifact</groupId>
<artifactId>with-layers.xml</artifactId>
<version>...</version>
<type>jar</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>**/layers.xml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
<configuration>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>反过来,行<configuration><!-- something like classpath:layers.xml --></configuration>变成了<configuration>${project.build.directory}/layers/layers.xml</configuration>。
发布于 2020-08-07 05:32:55
Spring Boot Maven Plugin的文档指出,您可以手动设置layers.xml的路径,那么为什么不让所有pom.xml指向相同的位置?
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.2.RELEASE</version>
<configuration>
<layers>
<enabled>true</enabled>
<configuration>${project.basedir}/../layers.xml</configuration>
</layers>
</configuration>
</plugin>
</plugins>
</build>
</project>/../表示项目目录的上一级。假设你在一个目录中有一堆项目,把layers.xml放在那里,它就可以工作了。
另一种方法是通过将Maven插件声明移动到所谓的parent POM来重用它。这是一种将一系列项目的POM文件的公用/共享部分移动到单个POM文件(父POM)的技术。Here's an example

https://stackoverflow.com/questions/63291567
复制相似问题