带有资源的Spring Boot应用程序的mvn软件包,请始终重新打包整个应用程序

时间:2019-02-07 23:43:52

标签: maven spring-boot package

即使在未对源代码进行任何修改的情况下,在带有资源目录的spring boot应用程序上运行“ mvn软件包”,也始终会重新打包整个模块。

要重现此问题,请运行以下说明:

  • git clone https://github.com/spring-guides/gs-spring-boot.git
  • cd gs-spring-boot / initial
  • mvn包
  • ls -l --time-style ='+%d-%m-%Y%H:%M:%S'target / *。jar
    • -rw-rw-r-- 1 mario mario 16224690 08-02-2019 00:19:37 target / gs-spring-boot-0.1.0.jar
  • mvn包
  • ls -l --time-style ='+%d-%m-%Y%H:%M:%S'target / *。jar
    • -rw-rw-r-- 1 mario mario 16224690 08-02-2019 00:19:37 target / gs-spring-boot-0.1.0.jar(相同日期:OK)

现在添加资源目录和application.properties文件:

  • mkdir src / main / resources
  • 触摸src / main / resources / application.properties

并重新运行测试:

  • mvn包
  • ls -l --time-style ='+%d-%m-%Y%H:%M:%S'target / *。jar

    • -rw-rw-r-- 1 mario mario 16225034 08-02-2019 00:29:09 target / gs-spring-boot-0.1.0.jar
  • 等待几秒钟

  • mvn软件包

  • ls -l --time-style ='+%d-%m-%Y%H:%M:%S'target / *。jar
    • -rw-rw-r-- 1 mario mario 16225034 08-02-2019 00:29:43 target / gs-spring-boot-0.1.0.jar(NOK)

Maven的输出是这样的:

mario@PRS-NB-005# mvn package
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-spring-boot 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ gs-spring-boot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ gs-spring-boot ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ gs-spring-boot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mario/prj/web/bbb/gs-spring-boot/initial/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ gs-spring-boot ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ gs-spring-boot ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ gs-spring-boot ---
[INFO] Building jar: /mario/prj/web/bbb/gs-spring-boot/initial/target/gs-spring-boot-0.1.0.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.5.RELEASE:repackage (default) @ gs-spring-boot ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.337 s
[INFO] Finished at: 2019-02-08T00:29:43+01:00
[INFO] Final Memory: 22M/308M
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:1)

看看有效的pom。 在那里,您将看到以下内容:

<build>
    ...
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>path/gs-spring-boot/initial/src/main/resources</directory>
            <includes>
                <include>**/application*.yml</include>
                <include>**/application*.yaml</include>
                <include>**/application*.properties</include>
            </includes>
        </resource>
       ...

由于<filtering>true</filtering>,它与每个mvn package一起创建了罐子。

此配置来自:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

如果不需要对application.properties进行过滤,则可以从头开始在pom.xml中覆盖。