首页 > 其他分享 >Maven

Maven

时间:2023-09-24 17:23:06浏览次数:34  
标签:project ... Maven POM test org

目录

Maven

Overview

Ref: https://maven.apache.org/guides/getting-started/index.html

Maven is a project management tool that provides developers with a complete project development life-cycle framework, and Maven is an open source project developed in pure Java under Apache

POM (Project Object Model) is the basic unit of the Maven system. It is stored in the root directory of the project in the form of an XML file named pom.xml.

Maven project default directory structure(${basedir} represents the current working directory):

Item Default
source code ${basedir}/src/main/java
resources ${basedir}/src/main/resources
tests ${basedir}/src/test
distributable JAR ${basedir}/target
complied byte code ${basedir}/target/classes

The Bulid Lifecycle

Ref: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.

Each lifecycle contains a series of construction phases. The phases have a sequence. When a phase of the life cycle is executed, it will be executed from the first phase of the life cycle to a specified phase in sequence.

standard life cycle:

  1. Clean

    phase: pre-clean, clean, post-clean

  2. Default

    phase: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, test-compile, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy

  3. Site

    phase: pre-site, site, post-site, site-deploy

phase explain
validate validate the project is correct and all necessary information is available
compile compile the source code of the project
test test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package take the compiled code and package it in its distributable format, such as a JAR.
verify run any checks on results of integration tests to ensure quality criteria are met
install install the package into the local repository, for use as a dependency in other projects locally
deploy done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

The POM

Ref: https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/test/java; and so on. When executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.

Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.

The Super POM is Maven's default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects.

The basic information of the project is defined in the POM, which is used to describe how the project is built, declare project dependencies, and so on.

When creating a POM, we need to provide the group (groupId) information of the project, the project name (artifactId) and the version information (version), which uniquely represent a POM object and project.

Node Description
groupId This is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects.
artifactId This is an Id of the project. This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository.
version This is the version of the project. Along with the groupId, It is used within an artifact's repository to separate versions from each other.

POM example:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <!-- project coordinates -->
    <groupId>cn.meyok.mavenlearn</groupId>
    <artifactId>pomlearn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <!-- POM inheritance -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/>
    </parent>
    
    <packaging>jar</packaging>
    
    <!-- related information -->
    <name>mavenlearn</name>
    <url>http://mavenlearn.meyok.cn</url>
    <description>mavenlearn</description>
    
    <!-- local repository path -->
    <localRepository>D:/myRepository/repository</localRepository>
    <!-- remote repository path -->
    <repositories>
        <repository>
            <id>meyok.lib</id>
            <url>http://download.meyok.org/maven/lib</url>
        </repository>
    </repositories>
    
    <!-- POM aggregation -->
    <modules>
        <module>user</module>
    </modules>
    
    <!-- 配置Profile,可选 -->
    <profiles>
        <profile>
            <id>test</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>test</value>
                </property>
            </activation>
            ....
        </profile>
        <profile>
            <id>normal</id>
            ....
        </profile>
        <profile>
            <id>prod</id>
            ....
        </profile>
    </profiles>
    
    <!-- 配置属性,可选 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.9</junit.version>
        ...
    </properties>
    
    <!-- 配置依赖 -->
    <!-- 依赖管理 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
            ...
        </dependencies>
    </dependencyManagement>

    <!-- 依赖导入 -->
    <dependencies>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>1.7.1</version>
            <scope>compile</scope>
            <optional>false</optional>
            <!-- 排除传递的依赖 -->
            <exclusions>
                <exclusion>
                    <groupId>org.apache.shiro</groupId>
                    <artifactId>shiro-cache</artifactId>
                </exclusion>
                ...
        	</exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        ...
	</dependencies>
    
    <!-- 配置构建配置 -->
    <build>
        <finalName>pomlearn</finalName>  
        <resources>  
            <resource>  
                <directory>src/main/java</directory>  
                <includes>  
                    <include>**/*.xml</include>  
                </includes>  
                <excludes>  
                    <exclude>**/*.txt</exclude>  
                    <exclude>**/*.doc</exclude>  
                </excludes>  
            </resource>
        </resources>
        <!-- 插件管理配置 -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.8</version>
                    <configuration>  
                        <source>1.8</source>  
                        <target>1.8</target>  
                        <encoding>UTF-8</encoding>   
                        <warName>WebMavenLearn</warName>  
                        ...
                    </configuration>  
                    <executions>
                        <execution>
                            <id>mavenlearn.meyok.cn</id>
                            <phase>pre-clean</phase>
                            <goals>
                                <goal>run</goal>
                                ...
                            </goals>
                             <configuration>
                                <tasks>
                                    <echo>预清理阶段</echo>
                                </tasks>
                        	</configuration>
                        </execution>
                    </executions>
                </plugin>
                ...
            </plugins>
        </pluginManagement>
        <!-- 插件配置 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>
            ...
        </plugins>
    </build>
    
</project>

标签:project,...,Maven,POM,test,org
From: https://www.cnblogs.com/meyok/p/17726256.html

相关文章

  • JHub开发之初始化Maven项目
    安装idea,安装git。这个应该是必备技能,跳过。安装jdk8+,我这里用的是java1.8.0_333。这个也应该是必备技能,跳过。安装Maven,也可以使用idea自带的maven。这个也应该是必备技能,跳过。设置maven仓库为阿里云。这个也应该是必备技能,跳过。安装Postman。这个......
  • springboot的Maven的镜像
     Maven的镜像<!--阿里镜像--><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyunmaven</name><url>http://maven.aliyun.com/nexus/content/repositories/central/</url>......
  • Maven 配置热部署
    Maven配置热部署参考文档:maven配置热部署-秒客网(miaokee.com)(22条消息)新版本Idea热部署无效问题处理_全栈高级工程师的博客-CSDN博客<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>r......
  • Maven 命令行构建 Java 项目
    Maven命令行构建Java项目(22条消息)使用Maven构建SpringBoot项目_Amazing_time的博客-CSDN博客_如何生成springboot项目的mvn构建命令xml-在Spring-BootIntro之后,"Unabletofindasuitablemainclass,pleaseadda'mainClass'属性"-IT工具网(coder.work)(2......
  • 解决IntelliJ IDEA执行maven打包,执行java -jar命令提示jar中没有主清单属性
    问题场景IDEA执行mvncleanpackage-DskipTest=true命令或者借助工具的Maven菜单进行打包操作,然后执行java-jarapp.jar命令后,提示jar中没有主清单属性D:\WorkSpace\demo\target>java-jardemo-SNAPSHOT.jardemo-SNAPSHOT.jar中没有主清单属性原因分析这个错误通常是......
  • maven和nodejs环境安装
    1.maven安装  wgethttps://dlcdn.apache.org/maven/maven-3/3.9.4/binaries/apache-maven-3.9.4-bin.tar.gz--no-check-certificate  参考连接:https://blog.csdn.net/yao583224426/article/details/1317396842.Node安装  nodejs官方:http://nodejs.cn/  cd/opt#......
  • Maven命令简介
    1.Maven生命周期  clean、validate、compile、test、package、verify、install、site、deploy.执行后面命令,前面周期自动执行。(可以跳过其中某一步骤,如:test,在mvninstall/package后加上Dmaven.test.skip=true或-DskipTests)  生命周期详细描述  Clean清理删除target目......
  • 解决本地maven仓库有jar包却还要读取私服依赖的问题
    请打开你自己的本地仓库,对应依赖路径下的_remote.repositories文件。如果是从远程仓库拉取的,这里一般是显示这个:junit-4.12.jar>alimaven=junit-4.12.pom>alimaven=这个说明是从阿里云远程仓库拉取的代码由于这里的配置,使得你每次下载,他都会优先从阿里云远程仓库拉代码,而不是优先......
  • 【效率提升】maven 转 gradle 实战
    一、灵魂三问1、gradle是什么?一个打包工具,是一个开源构建自动化工具,足够灵活,可以构建几乎任何类型的软件,高性能、可扩展、能洞察等。其中洞察,可以用于分析构建过程中数据,提供分析参考,方便排查问题和不断优化构建性能,以下一次编译分析报告。2、有什么优势参考官方文章,针对包......
  • org/springframework/boot/maven/RepackageMojo has been compiled by a more recent
    项目场景:项目中执行clean,再执行install时报错,错误如下org/springframework/boot/maven/RepackageMojohasbeencompiledbyamorerecentversionoftheJavaRuntime(classfileversion61.0),thisversionoftheJavaRuntimeonlyrecognizesclassfileversionsupt......