Sco*_* C. 163 maven parent-pom spring-boot
是否有特定的推荐方法将spring-boot父pom包含在已经拥有所需父POM的项目中?
对于需要从组织父级扩展的项目,您有什么建议(这是非常常见的,甚至很多/大多数项目都发布到Maven中心,具体取决于它们来自的支线回购).大多数构建内容与创建可执行JAR(例如,运行嵌入式Tomcat/Jetty)有关.有一些方法可以构建事物,以便您可以获得所有依赖项而无需从父项扩展(类似于组合与继承).你无法通过这种方式获得构建内容.
因此,最好在所需的父POM中包含所有spring-boot父pom,或者只是在项目POM文件中包含POM依赖项.
其他选择?
TIA,
斯科特
Dav*_*yer 165
您可以使用spring-boot-starter-parent作为"bom"(参见Spring和Jersey其他支持此功能的项目),并将其仅包含在scope = import的依赖关系管理部分中.这样您就可以获得很多使用它的好处(即依赖管理)而不替换实际父级中的设置.
它做的另外两件事是
Spring Boot文档中提供的示例:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
Sur*_*oen 36
使用1.5.9.RELEASE更新2018-01-04.
我在这里有完整的代码和可运行的示例https://www.surasint.com/spring-boot-with-no-parent-example/
你需要这个作为基础
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
但这还不够,你还需要为spring-boot-maven-plugin明确定义目标(如果你使用Spring Boot作为父级,你不必明确定义它)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springframework.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
否则你无法构建可执行的jar或war.
还没有,如果你使用JSP,你需要这样:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Run Code Online (Sandbox Code Playgroud)
否则,您将收到以下错误消息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-boot-09: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executi
ng in update mode) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
不,如果您使用带有"@"而不是"$ {}"的Spring Boot的Maven配置文件和资源过滤器,这仍然是不够的(如此示例https://www.surasint.com/spring-boot-maven -resource-filter /).然后你需要明确添加它
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
而这在
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
请参阅链接https://www.surasint.com/spring-boot-with-no-parent-example/中的示例.
| 归档时间: |
|
| 查看次数: |
68942 次 |
| 最近记录: |