Alice52 / java-ocean

java-tutorial .We intend to explain Java knowledge in this repository.
MIT License
0 stars 0 forks source link

[maven] maven build #102

Closed Alice52 closed 11 months ago

Alice52 commented 4 years ago
  1. packaging tag

    • jar
    • war
    • pom
  2. dependencyManagement and dependencies

    • dependencyManagement: 提供管理依赖版本号的方式, 一般用于 父 POM
      • 只声明依赖, 并不会引入实现, 因此子项目子项目需要显示声明需要用的依赖
      • 可以让所有的引用一个依赖, 且不需要显式列出版本号
      • Maven 版本号确定会沿着父项目向上找, 知道最顶层的父项目, 使用其中的版本号
      • 子项目没有才会寻找并使用父项目的
      • 子项目有特定需求可以自己指定 version
  3. maven 打包没有 jar, no main manifest attribute, in xx.jar 或者 SpringApplication ClassNotFound

    • parent

      <build>
       <plugins>
           <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <version>2.1.7.RELEASE</version>
               <executions>
                   <execution>
                       <goals>
                           <goal>repackage</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>
       </plugins>
      </build>
    • common: 两个注释的地方2选1吧

      <!-- Failed to execute goal repackage failed: Unable to find main class -> [Help 1] -->
      <properties>
       <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
      </properties>
      
      <build>
       <plugins>
           <plugin>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-maven-plugin</artifactId>
               <!-- 可运行的 jar -->
               <configuration>
                   <classifier>exec</classifier>
               </configuration>
           </plugin>
       </plugins>
      </build>
    • module: 正常使用


Reference

  1. https://blog.csdn.net/qq_42897427/article/details/104826365
  2. mavne build: https://blog.csdn.net/DamonREN/article/details/85091900
Alice52 commented 11 months ago
maven gradle note
compile compile/implementation/api 编译打包都需要
optional 编译打包都需要(没有传递性)
provided compileOnly 只编译
runtime runtime[Only] 编译参与打包不参与
test testCompile[Implementation]
system classpath

image