POM文件管理依赖包

POM文件是一个xml的文件



    4.0.0

    org.springframework
    gs-maven
    jar
    0.1.0

    
        1.8
        1.8
    

    
        
            
                org.apache.maven.plugins
                maven-shade-plugin
                2.1
                
                    
                        package
                        
                            shade
                        
                        
                            
                                
                                    hello.HelloWorld
                                
                            
                        
                    
                
            
        
    

https://spring.io/guides/gs/maven/#scratch
在spring 官网中指出,一个基本的POM文件只需要4个标签

With the exception of the optional element, this is the simplest possible pom.xml file necessary to build a Java project. It includes the following details of the project configuration:

  • . POM model version (always 4.0.0).
  • . Group or organization that the project belongs to. Often expressed as an inverted domain name.
  • . Name to be given to the project’s library artifact (for example, the name of its JAR or WAR file).
  • . Version of the project that is being built.
  • How the project should be packaged. Defaults to "jar" for JAR file packaging. Use "war" for WAR file packaging.

================================================================
多模块web项目POM文件之间的关系:

  1. 只有web这个模块是按war打包
  2. 当没有使用时,即缺省时,会被maven打包成jar
  3. 的值是POM时,会把它的module打包,但是它自己不会有target。一个模块用POM的方式打包时,不可以被其他模块直接依赖(因为它没有打包出任何war和jar的东西,它只是可以打包出它的模块)

一般项目只有父模块或者是相对父模块是将的值设置为pom的,打包完会在各个子模块的target下看到打出的包若子模块a中嵌套子模块b和子模块c,那么a子模块也可设置为pom的打包形式,但是其他模块(如d)不能直接引用a,要直接引用b,或者c

=================================================================
POM文件之间的继承和聚合:

每个模块都有自己的POM文件,POM文件要注意的两个特性是继承和聚合。

1)看聚合关系,查看父层的pom,pom文件通过标签将模块聚合起来
2)看继承关系,查看子层的pom,pom文件通过指定继承父层

  • 子pom 会直接继承 父pom 中声明的属性
  • 父pom 中仅仅使用 依赖的包,会被 子pom 直接继承(不需要显式依赖) 具有依赖传递性,就是可以层层传递
  • 父pom 中仅仅使用 依赖的插件,会被 子pom 直接继承(不需要显式依赖)
  • 父pom中可以使用来统一管理jar包和插件pugin,不会被 子pom 直接继承。此时子pom如果希望继承该包或插件,则需要显式依赖,同时像 等配置项可以不被显式写出,默认从父pom继承

参考:
https://blog.csdn.net/qq_32331073/article/details/77197360
https://blog.csdn.net/f45056231p/article/details/84942531

=================================================================
mvn的一些主要命令:

  • mvn complie
    This will run Maven, telling it to execute the compile goal. When it’s finished, you should find the compiled .class files in the target/classes directory.
    因为我们不是解决部署.class 文件所以还需要打包

  • mvn package
    The package goal will compile your Java code, run any tests, and finish by packaging the code up in a JAR file within the target directory. The name of the JAR file will be based on the project’s and .

  • mvn install
    Maven also maintains a repository of dependencies on your local machine (usually in a .m2/repository directory in your home directory) for quick access to project dependencies. If you’d like to install your project’s JAR file to that local repository, then you should invoke the install goal
    The install goal will compile, test, and package your project’s code and then copy it into the local dependency repository, ready for another project to reference it as a dependency.

  • mvn test
    maven use a plugin called "surefire" to run unit tests. The default configuration of this plugin complies and runs all classes in src/test/java with a name matching Test
    大白话就是当你引进了junit的包之后,在maven的加成下,使用@Test的注解,maven能找到并直接调用
    =================================================================
    标签
    By default, all dependencies are scoped as compile dependencies. That is, they should be available at compile-time (and if you were building a WAR file, including in the /WEB-INF/libs folder of the WAR). Additionally, you may specify a element to specify one of the following scopes:

  • provided - Dependencies that are required for compiling the project code, but that will be provided at runtime by a container running the code (e.g., the Java Servlet API).
    【这一条我又疑问,也就是的值为complie的话,放到容器里就没有啦?】

  • test - Dependencies that are used for compiling and running tests, but not required for building or running the project’s runtime code.
    =================================================================

你可能感兴趣的:(POM文件管理依赖包)