小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Maven項(xiàng)目管理工具:Maven自動(dòng)化構(gòu)建

 碼農(nóng)9527 2021-09-30

    Maven自動(dòng)化構(gòu)建是一種方案,即當(dāng)某個(gè)項(xiàng)目構(gòu)建完成后(特別是有代碼更新的情況下),所有依賴它的相關(guān)項(xiàng)目也應(yīng)該開始構(gòu)建過程,以確保這些項(xiàng)目的穩(wěn)定運(yùn)行。

    Maven的自動(dòng)化構(gòu)建主要通過如下兩種方案實(shí)現(xiàn):

    使用maven-invoker-plugin插件。

    使用持續(xù)集成(CI)服務(wù)器自動(dòng)管理構(gòu)建自動(dòng)化,例如Jenkins(了解即可)。

    使用maven-invoker-plugin插件

    Maven社區(qū)提供了一個(gè)名為maven-invoker-plugin的插件,該插件能夠用來在一組項(xiàng)目上執(zhí)行構(gòu)建工作,并檢查每個(gè)項(xiàng)目是否構(gòu)建成功,通過它就可以實(shí)現(xiàn)Maven的自動(dòng)化構(gòu)建。

    如下圖所示,在D:\maven目錄下有3個(gè)Maven項(xiàng)目。

    其中,helloMaven項(xiàng)目的pom.xml配置如下。

<project xmlns="http://maven./POM/4.0.0"
   xmlns:xsi="http://www./2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>net.biancheng.www</groupId>
 <artifactId>helloMaven</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>helloMaven</name>
 <url>http://maven.</url>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <!-- 添加invoker 插件 -->
   <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-invoker-plugin</artifactId>
 <version>3.2.2</version>
 <configuration>
  <debug>true</debug>
  <!--設(shè)置 invkoer插件 添加的 pom 文件所在的文件夾  -->
  <projectsDirectory>D:\maven</projectsDirectory>
  <!-- 設(shè)置 invkoer插件 添加的 pom 文件 -->
  <pomIncludes>
   <pomInclude>secondMaven\pom.xml</pomInclude>
   <pomInclude>thirdMaven\pom.xml</pomInclude>
  </pomIncludes>
 </configuration>
 <executions>
  <execution>
   <id>id-integration-test</id>
   <!-- 執(zhí)行的目標(biāo) -->
   <goals>
    <goal>run</goal>
   </goals>
  </execution>
 </executions>
   </plugin>
  </plugins>
 </build>
</project>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748復(fù)制代碼類型:[java]

    以上配置中,在build的plugins子元素中使用了一個(gè)plugin元素聲明了一個(gè)構(gòu)建期的插件maven-invoker-plugin,該插件配置中各元素含義如下:

    groupId:插件的項(xiàng)目組id;

    artifactId:插件的項(xiàng)目或模塊id;

    version:插件的版本;

    projectsDirectory:需要構(gòu)建項(xiàng)目的目錄,該元素可單獨(dú)使用,表示該目錄下的所有Maven項(xiàng)目都會(huì)在當(dāng)前項(xiàng)目構(gòu)建完成后開始構(gòu)建;

    pomIncludes:該元素內(nèi)可以聲明一個(gè)或多個(gè)pomInclude元素,需與projectDirectory元素配合使用,共同指定需要構(gòu)建項(xiàng)目的pom.xml。

    secondMaven項(xiàng)目依賴于helloMaven,其pom.xml配置如下。

<project xmlns="http://maven./POM/4.0.0" xmlns:xsi="http://www./2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>net.biancheng.www</groupId>
 <artifactId>secondMaven</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>secondMaven</name>
 <url>http://maven.</url>
 <build>
  <plugins>
   <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-site-plugin</artifactId>
 <version>3.7.1</version>
   </plugin>
   <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-project-info-reports-plugin</artifactId>
 <version>3.0.0</version>
   </plugin>
  </plugins>
 </build>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>net.biancheng.www</groupId>
   <artifactId>helloMaven</artifactId>
   <scope>system</scope>
   <version>1.0-SNAPSHOT</version>
   <systemPath>D:\maven\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar</systemPath>
  </dependency>
 </dependencies>
</project>123456789101112131415161718192021222324252627282930313233343536373839復(fù)制代碼類型:[java]

    thirdMaven項(xiàng)目依賴于helloMaven,其pom.xml配置如下。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven./POM/4.0.0" xmlns:xsi="http://www./2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>net.biancheng.www</groupId>
 <artifactId>thirdMaven</artifactId>
 <version>1.0-SNAPSHOT</version>
 <name>thirdMaven</name>
 <!-- FIXME change it to the project's website -->
 <url>http://www.</url>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.7</maven.compiler.source>
  <maven.compiler.target>1.7</maven.compiler.target>
 </properties>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.11</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>net.biancheng.www</groupId>
   <artifactId>helloMaven</artifactId>
   <version>1.0-SNAPSHOT</version>
  </dependency>
 </dependencies>
 <build>
  <pluginManagement>
   <plugins>
 <plugin>
  <artifactId>maven-clean-plugin</artifactId>
  <version>3.1.0</version>
 </plugin>
 <plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
 </plugin>
 <plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
 </plugin>
 <plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.1</version>
 </plugin>
 <plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.2</version>
 </plugin>
 <plugin>
  <artifactId>maven-install-plugin</artifactId>
  <version>2.5.2</version>
 </plugin>
 <plugin>
  <artifactId>maven-deploy-plugin</artifactId>
  <version>2.8.2</version>
 </plugin>
 <plugin>
  <artifactId>maven-site-plugin</artifactId>
  <version>3.7.1</version>
 </plugin>
 <plugin>
  <artifactId>maven-project-info-reports-plugin</artifactId>
  <version>3.0.0</version>
 </plugin>
   </plugins>
  </pluginManagement>
 </build>
</project>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071復(fù)制代碼類型:[java]

    打開命令控制臺,執(zhí)行如下命令,查看maven-invoker-plugin插件綁定的目標(biāo)。

>mvn help:describe -Dplugin=invoker1復(fù)制代碼類型:[java]

    Maven命令執(zhí)行結(jié)果如下。

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ standalone-pom ---
Downloading from central: https://repo.maven./maven2/org/apache/maven/plugins/maven-invoker-plugin/maven-metadata.xmlDownloaded from central: https://repo.maven./maven2/org/apache/maven/plugins/maven-invoker-plugin/maven-metadata.xml (888 B at 539 B/s)[INFO] org.apache.maven.plugins:maven-invoker-plugin:3.2.2
Name: Apache Maven Invoker Plugin
Description: The Maven Invoker Plugin is used to run a set of Maven projects.
  The plugin can determine whether each project execution is successful, and
  optionally can verify the output generated from a given project execution.
Group Id: org.apache.maven.plugins
Artifact Id: maven-invoker-plugin
Version: 3.2.2
Goal Prefix: invoker
This plugin has 6 goals:
invoker:help
  Description: Display help information on maven-invoker-plugin.
 Call mvn invoker:help -Ddetail=true -Dgoal=<goal-name> to display parameter
 details.
invoker:install
  Description: Installs the project artifacts of the main build into the
 local repository as a preparation to run the sub projects. More precisely,
 all artifacts of the project itself, all its locally reachable parent POMs
 and all its dependencies from the reactor will be installed to the local
 repository.
invoker:integration-test
  Description: Searches for integration test Maven projects, and executes
 each, collecting a log in the project directory, will never fail the build,
 designed to be used in conjunction with the verify mojo.
invoker:report
  Description: Generate a report based on the results of the Maven
 invocations. Note: This mojo doesn't fork any lifecycle, if you have a
 clean working copy, you have to use a command like mvn clean
 integration-test site to ensure the build results are present when this
 goal is invoked.
  Note: This goal should be used as a Maven report.
invoker:run
  Description: Searches for integration test Maven projects, and executes
 each, collecting a log in the project directory, and outputting the results
 to the command line.
invoker:verify
  Description: Checks the results of maven-invoker-plugin based integration
 tests and fails the build if any tests failed.
For more information, run 'mvn help:describe [...] -Ddetail'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.467 s
[INFO] Finished at: 2021-03-05T10:03:15+08:00
[INFO] ------------------------------------------------------------------------123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354復(fù)制代碼類型:[java]

    由以上執(zhí)行結(jié)果可知,maven-invoker-plugin插件綁定的Maven生命周期階段為integration-test及其以后,所以執(zhí)行integration-test階段及其以后的都可以觸發(fā)該插件。

    跳轉(zhuǎn)到D:\maven\helloMaven目錄下,執(zhí)行如下Maven命令。

mvn clean install1復(fù)制代碼類型:[java]

    執(zhí)行結(jié)果如下。

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< net.biancheng.www:helloMaven >--------------------
[INFO] Building helloMaven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ helloMaven ---
[INFO] Deleting d:\maven\helloMaven\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloMaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory d:\maven\helloMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloMaven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 2 source files to d:\maven\helloMaven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloMaven ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory d:\maven\helloMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloMaven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to d:\maven\helloMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ helloMaven ---
[INFO] Surefire report directory: d:\maven\helloMaven\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running net.biancheng.www.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ helloMaven ---
[INFO] Building jar: d:\maven\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-invoker-plugin:3.2.2:run (id-integration-test) @ helloMaven ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[WARNING] Filtering of parent/child POMs is not supported without cloning the projects
[INFO] Building: secondMaven\pom.xml
[INFO]  secondMaven\pom.xml .............................. SUCCESS (2.6 s)[INFO] Building: thirdMaven\pom.xml
[INFO]  thirdMaven\pom.xml ............................... SUCCESS (3.7 s)[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 2, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ helloMaven ---
[INFO] Installing d:\maven\helloMaven\target\helloMaven-1.0-SNAPSHOT.jar to D:\myRepository\repository\net\biancheng\www\helloMaven\1.0-SNAPSHOT\helloMaven-1.0-SNAPSHOT.jar
[INFO] Installing d:\maven\helloMaven\pom.xml to D:\myRepository\repository\net\biancheng\www\helloMaven\1.0-SNAPSHOT\helloMaven-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.335 s
[INFO] Finished at: 2021-03-05T10:20:26+08:00
[INFO] ------------------------------------------------------------------------12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061復(fù)制代碼類型:[java]

    通過以上執(zhí)行過程可以看到,在helloMaven構(gòu)建完成后,Invoker插件對secondMaven和thirdMaven也進(jìn)行了構(gòu)建。

    注意:secondMaven和thirdMaven是否依賴于helloMaven,不會(huì)影響Invoker插件是否對它們進(jìn)行構(gòu)建。即使secondMaven和thirdMaven都不依賴于helloMaven,只要在Invoker插件中配置了這些項(xiàng)目,Invoker插件也依然會(huì)在helloMaven構(gòu)建完成后,對它們進(jìn)行構(gòu)建。

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多