[maven] 实现使用 plugin 及 properties 简述

news2024/11/24 18:28:55

[maven] 实现&使用 plugin 及 properties 简述

这章内容,我个人感觉可看可不看……?

不过课都上了,笔记 📒 补完才对得起自己嘛

plugins

主要讲一下 maven 的 plugin 时怎么实现的,以及项目中怎么调用自己实现的 maven plugin

一般来说这个功能的确比较少用到,大多数情况下市场上已有的 plugin 是可以满足大部分需求了

新建项目

这次新建的是 plugin 项目,需要注意:

在这里插入图片描述

注意 POM 里的 packaging 类型为 maven-plugin

<?xml version="1.0" encoding="UTF-8"?>


<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.ga</groupId>
	<artifactId>plugindemo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>maven-plugin</packaging>

	<dependencies>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-plugin-api</artifactId>
			<version>${maven-plugin-api.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.maven.plugin-tools</groupId>
			<artifactId>maven-plugin-annotations</artifactId>
			<version>${maven-plugin-annotations.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-project</artifactId>
			<version>${maven-project.version}</version>
		</dependency>
	</dependencies>


	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-plugin-plugin</artifactId>
					<version>${maven-plugin-plugin.version}</version>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

	<properties>
		<maven-plugin-api.version>3.6.2</maven-plugin-api.version>
		<maven-plugin-annotations.version>3.6.0</maven-plugin-annotations.version>
		<maven-project.version>2.2.1</maven-project.version>
		<maven-plugin-plugin.version>3.6.4</maven-plugin-plugin.version>
		<maven.compiler.source>17</maven.compiler.source>
		<maven.compiler.target>17</maven.compiler.target>
		<java.version>17</java.version>
	</properties>

</project>

这个是只要会用到的配置,和 eclipse 内置的 pom 比起来少了很多的内容,如 test 相关的配置全都被移除了,这里只留下需要实现 plugin 的核心模块

Java 中默认的 MOJO 如下:

/**
 * Goal which touches a timestamp file.
 */
@Mojo(name = "touch", defaultPhase = LifecyclePhase.PROCESS_SOURCES)
public class MyMojo extends AbstractMojo {
	/**
	 * Location of the file.
	 */
	@Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true)
	private File outputDirectory;

	public void execute() throws MojoExecutionException {
	}
}

就像 POJO 代表 Plain Old Java Object,MOJO 代表的就是 Maven plain Old Java Object

可以看到实现一个 MOJO 需要 extends AbstractMojo,而里面最重要的 execute 在执行出问题的时候抛出的是 MojoExecutionException

实现 MOJO 代码

其实主要就是调用 getLog() 在命令行进行输出:

@Mojo(name = "info-renderer", defaultPhase = LifecyclePhase.COMPILE)
public class ProjectInfoMojo extends AbstractMojo {

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		getLog().info("Mojos are cool");
	}
}

getLog() 是由 AbstractMojo 提供的一个方法,其本身会返回一个 Log 实例以供调用,比较常见的用法就是调用 instance 上的 info, debug, error 在命令行输出相应的信息

运行 plugin

plugin 执行的语法为: mvn groupId:artifactId:version:goal

❯ mvn com.ga:plugindemo:info-renderer
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/com/ga/plugindemo/maven-metadata.xml
[INFO]
[INFO] -------------------------< com.ga:plugindemo >--------------------------
[INFO] Building plugindemo 0.0.1-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default-cli) @ plugindemo ---
[INFO] Mojos are cool
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.026 s
[INFO] Finished at: 2023-09-19T00:28:59-04:00
[INFO] ------------------------------------------------------------------------

缩写

缩写这块我是没有成功过,不过根据官方文档 Shortening the Command Line 上说,需要修改 .m2 下的 settings.xml,大概如下:

<pluginGroups>
  <pluginGroup>sample.plugin</pluginGroup>
</pluginGroups>

接下来执行这条指令就好了:mvn projectinfo:info-renderer

相当于说把 groupId 配置到 pluginGroup 里了,不幸的是尽管在 com.ga 下面找到了自己的 plugin,但是还是没发成功运行缩写:

❯ tree ~/.m2/repository/com/ga
/Users/usr/.m2/repository/com/ga
├── maven-metadata-local.xml
├── plugindemo
│   ├── 0.0.1-SNAPSHOT
│   │   ├── _remote.repositories
│   │   ├── maven-metadata-local.xml
│   │   ├── plugindemo-0.0.1-SNAPSHOT.jar
│   │   └── plugindemo-0.0.1-SNAPSHOT.pom
│   ├── maven-metadata-local.xml
│   └── resolver-status.properties
└── resolver-status.properties

3 directories, 8 files

这有可能跟之前 xml 里的 proxy 有关,不是很确定……

不过不影响在其他项目中调用,就没继续琢磨了

调用项目信息

主要通过 annotation 实现,如下面添加了对项目的 annotation:

@Mojo(name = "info-renderer", defaultPhase = LifecyclePhase.COMPILE)
public class ProjectInfoMojo extends AbstractMojo {

	@Parameter(defaultValue = "${project}", required = true, readonly = true)
	MavenProject project;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		getLog().info("Mojos are cool");
		getLog().info("Project Name: " + project.getName());
		getLog().info("Artifact Id: " + project.getArtifactId());
	}

}

终端上就能获取项目名称、artifact id 之类的信息:

❯ mvn com.ga:plugindemo:info-renderer
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.ga:plugindemo >--------------------------
[INFO] Building plugindemo 0.0.1-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default-cli) @ plugindemo ---
[INFO] Mojos are cool
[INFO] Project Name: plugindemo
[INFO] Artifact Id: plugindemo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.313 s
[INFO] Finished at: 2023-09-19T01:56:26-04:00
[INFO] ------------------------------------------------------------------------

在这里插入图片描述

访问依赖 dependencies

依赖也是保存在 project 里,这里使用了一个 lambda expression 遍历所有的依赖:

project.getDependencies().forEach(d -> getLog().info(d.toString()));

输出结果:

❯ mvn com.ga:plugindemo:info-renderer
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.ga:plugindemo >--------------------------
[INFO] Building plugindemo 0.0.1-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default-cli) @ plugindemo ---
[INFO] Mojos are cool
[INFO] Project Name: plugindemo
[INFO] Artifact Id: plugindemo
[INFO] Dependency {groupId=org.apache.maven, artifactId=maven-plugin-api, version=3.6.2, type=jar}
[INFO] Dependency {groupId=org.apache.maven.plugin-tools, artifactId=maven-plugin-annotations, version=3.6.0, type=jar}
[INFO] Dependency {groupId=org.apache.maven, artifactId=maven-project, version=2.2.1, type=jar}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.321 s
[INFO] Finished at: 2023-09-19T01:58:10-04:00
[INFO] ------------------------------------------------------------------------

传入参数

从命令行/配置中获取参数的方法如下:

List<Dependency> dependencies = project.getDependencies();
dependencies.stream().filter(d -> scope != null && scope.equals(d.getScope()))
				.forEach(d -> getLog().info(d.toString()));

上面这个代码会获取 scope 这个参数,并且过滤掉所有与传入的 scope 不相符的依赖:

❯ mvn com.ga:plugindemo:info-renderer -Dscope=test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.ga:plugindemo >--------------------------
[INFO] Building plugindemo 0.0.1-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default-cli) @ plugindemo ---
[INFO] Mojos are cool
[INFO] Project Name: plugindemo
[INFO] Artifact Id: plugindemo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.365 s
[INFO] Finished at: 2023-09-19T02:03:30-04:00
[INFO] ------------------------------------------------------------------------

上面我已经提到过,所有和测试相关的 pom 都移除了,这里自然不会看到跟测试有关的 pom。而 scope 为 provided 的有一个 org.apache.maven.plugin-tools,所以就会在下面显示出来:

# change scope to provided
❯ mvn com.ga:plugindemo:info-renderer -Dscope=provided
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.ga:plugindemo >--------------------------
[INFO] Building plugindemo 0.0.1-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default-cli) @ plugindemo ---
[INFO] Mojos are cool
[INFO] Project Name: plugindemo
[INFO] Artifact Id: plugindemo
[INFO] Dependency {groupId=org.apache.maven.plugin-tools, artifactId=maven-plugin-annotations, version=3.6.0, type=jar}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.371 s
[INFO] Finished at: 2023-09-19T02:04:30-04:00
[INFO] ------------------------------------------------------------------------

在其他项目中使用 plugin

其实和调用其他的 plugin 一样,pom 如下:

	<build>
		<plugins>
			<plugin>
				<groupId>com.ga</groupId>
				<artifactId>plugindemo</artifactId>
				<version>0.0.1-SNAPSHOT</version>
				<executions>
					<execution>
						<goals>
							<goal>info-renderer</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<scope>test</scope>
				</configuration>
			</plugin>
		</plugins>
	</build>

执行结果如下:

在这里插入图片描述

❯ mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.ga:use-plugin >--------------------------
[INFO] Building use-plugin 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ use-plugin ---
[INFO] Deleting /Users/usr/study/maven/use-plugin/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ use-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/usr/study/maven/use-plugin/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ use-plugin ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/usr/study/maven/use-plugin/target/classes
[INFO]
[INFO] --- plugindemo:0.0.1-SNAPSHOT:info-renderer (default) @ use-plugin ---
[INFO] Mojos are cool
[INFO] Project Name: use-plugin
[INFO] Artifact Id: use-plugin
[INFO] Dependency {groupId=junit, artifactId=junit, version=4.11, type=jar}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.220 s
[INFO] Finished at: 2023-09-20T20:52:37-04:00
[INFO] ------------------------------------------------------------------------

在这里插入图片描述

properties

properties 这里……主要就是用到再查的感觉吧,常用的就是之前已经写过的,通过 properties 对使用的依赖进行版本管理的方法

这里用到的 maven-antrun-plugin 是打包用的插件

命令行输出所有属性

这里用的项目是之前 [maven] maven 创建 web 项目并嵌套项目 中实现的项目,POM 修改如下:

<plugins>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-antrun-plugin</artifactId>
		<version>1.7</version>
		<executions>
			<execution>
				<phase>validate</phase>
				<goals>
					<goal>run</goal>
				</goals>
				<configuration>
					<tasks>
						<echoproperties />
					</tasks>
				</configuration>
			</execution>
		</executions>
	</plugin>
</plugins>

需要注意的是 echoproperties 这个属性在后来的版本被移除了,这里跟着教程使用 1.7 可以输出所有的属性:

main:
[echoproperties] #Ant properties
[echoproperties] #Wed Sep 20 21:02:03 EDT 2023
[echoproperties] java.specification.version=17
[echoproperties] ant.project.name=maven-antrun-
[echoproperties] sun.jnu.encoding=UTF-8
[echoproperties] project.build.testOutputDirectory=/Users/usr/study/maven/parent/productweb/target/test-classes
[echoproperties] project.name=productweb Maven Webapp
[echoproperties] settings.localRepository=/Users/usr/.m2/repository
[echoproperties] sun.arch.data.model=64
[echoproperties] java.vendor.url=https\://www.microsoft.com
[echoproperties] maven.dependency.org.springframework.spring-aop.jar.path=/Users/usr/.m2/repository/org/springframework/spring-aop/6.0.11/spring-aop-6.0.11.jar
[echoproperties] maven.dependency.org.springframework.spring-beans.jar.path=/Users/usr/.m2/repository/org/springframework/spring-beans/6.0.11/spring-beans-6.0.11.jar
[echoproperties] sun.boot.library.path=/Users/usr/.sdkman/candidates/java/17.0.8.1-ms/lib
[echoproperties] sun.java.command=org.codehaus.plexus.classworlds.launcher.Launcher validate
[echoproperties] jdk.debug=release
[echoproperties] maven.home=/Users/usr/.sdkman/candidates/maven/current
[echoproperties] sun.stderr.encoding=UTF-8
[echoproperties] java.specification.vendor=Oracle Corporation
[echoproperties] project.artifactId=productweb
[echoproperties] java.version.date=2023-08-24
[echoproperties] project.version=1.0
[echoproperties] java.home=/Users/usr/.sdkman/candidates/java/17.0.8.1-ms
[echoproperties] org.opentest4j\:opentest4j\:jar=/Users/usr/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar
[echoproperties] basedir=/Users/usr/study/maven/parent/productweb
[echoproperties] file.separator=/
[echoproperties] java.vm.compressedOopsMode=Zero based
[echoproperties] project.packaging=war
[echoproperties] line.separator=\n
[echoproperties] org.junit.jupiter\:junit-jupiter-api\:jar=/Users/usr/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar
[echoproperties] sun.stdout.encoding=UTF-8
[echoproperties] java.specification.name=Java Platform API Specification
[echoproperties] java.vm.specification.vendor=Oracle Corporation
[echoproperties] org.junit.platform\:junit-platform-engine\:jar=/Users/usr/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar
[echoproperties] org.springframework\:spring-beans\:jar=/Users/usr/.m2/repository/org/springframework/spring-beans/6.0.11/spring-beans-6.0.11.jar
[echoproperties] sun.management.compiler=HotSpot 64-Bit Tiered Compilers
[echoproperties] java.runtime.version=17.0.8.1+1-LTS
[echoproperties] maven.dependency.org.springframework.spring-expression.jar.path=/Users/usr/.m2/repository/org/springframework/spring-expression/6.0.11/spring-expression-6.0.11.jar
[echoproperties] user.name=usr
[echoproperties] org.junit.jupiter\:junit-jupiter-engine\:jar=/Users/usr/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar
[echoproperties] file.encoding=UTF-8
[echoproperties] guice.disable.misplaced.annotation.check=true
[echoproperties] java.vendor.version=Microsoft-8297089
[echoproperties] localRepository=\      id\: local\n      url\: file\:///Users/usr/.m2/repository/\n   layout\: default\nsnapshots\: [enabled \=> true, update \=> always]\n releases\: [enabled \=> true, update \=> always]\n
[echoproperties] java.io.tmpdir=/var/folders/j_/r1vl8z45443b115dbx6pzvn80000gq/T/
[echoproperties] org.springframework\:spring-expression\:jar=/Users/usr/.m2/repository/org/springframework/spring-expression/6.0.11/spring-expression-6.0.11.jar
[echoproperties] java.version=17
[echoproperties] java.vm.specification.name=Java Virtual Machine Specification
[echoproperties] maven.dependency.org.junit.platform.junit-platform-commons.jar.path=/Users/usr/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar
[echoproperties] org.springframework\:spring-aop\:jar=/Users/usr/.m2/repository/org/springframework/spring-aop/6.0.11/spring-aop-6.0.11.jar
[echoproperties] native.encoding=UTF-8
[echoproperties] ant.version=Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[echoproperties] java.library.path=/Users/usr/Library/Java/Extensions\:/Library/Java/Extensions\:/Network/Library/Java/Extensions\:/System/Library/Java/Extensions\:/usr/lib/java\:.
[echoproperties] java.vendor=Microsoft
[echoproperties] classworlds.conf=/Users/usr/.sdkman/candidates/maven/current/bin/m2.conf
[echoproperties] sun.io.unicode.encoding=UnicodeBig
[echoproperties] library.jansi.path=/Users/usr/.sdkman/candidates/maven/current/lib/jansi-native
[echoproperties] ant.file.maven-antrun-=/Users/usr/study/maven/parent/productweb/target/antrun/build-main.xml
[echoproperties] project.build.directory=/Users/usr/study/maven/parent/productweb/target
[echoproperties] maven.dependency.org.springframework.spring-jcl.jar.path=/Users/usr/.m2/repository/org/springframework/spring-jcl/6.0.11/spring-jcl-6.0.11.jar
[echoproperties] java.class.path=/Users/usr/.sdkman/candidates/maven/current/boot/plexus-classworlds-2.6.0.jar
[echoproperties] org.apiguardian\:apiguardian-api\:jar=/Users/usr/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
[echoproperties] java.vm.vendor=Microsoft
[echoproperties] org.apache.geronimo.specs\:geronimo-servlet_3.0_spec\:jar=/Users/usr/.m2/repository/org/apache/geronimo/specs/geronimo-servlet_3.0_spec/1.0/geronimo-servlet_3.0_spec-1.0.jar
[echoproperties] project.groupId=com.goldenaarcher.product
[echoproperties] user.timezone=America/New_York
[echoproperties] maven.conf=/Users/usr/.sdkman/candidates/maven/current/conf
[echoproperties] project.build.outputDirectory=/Users/usr/study/maven/parent/productweb/target/classes
[echoproperties] java.vm.specification.version=17
[echoproperties] os.name=Mac OS X
[echoproperties] junit.version=5.10.0
[echoproperties] ant.file.type.maven-antrun-=file
[echoproperties] sun.java.launcher=SUN_STANDARD
[echoproperties] user.country=US
[echoproperties] sun.cpu.endian=little
[echoproperties] project.build.testSourceDirectory=/Users/usr/study/maven/parent/productweb/src/test/java
[echoproperties] user.home=/Users/usr
[echoproperties] user.language=en
[echoproperties] maven.dependency.org.junit.jupiter.junit-jupiter-engine.jar.path=/Users/usr/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.10.0/junit-jupiter-engine-5.10.0.jar
[echoproperties] ant.java.version=1.7
[echoproperties] org.springframework\:spring-jcl\:jar=/Users/usr/.m2/repository/org/springframework/spring-jcl/6.0.11/spring-jcl-6.0.11.jar
[echoproperties] maven.dependency.com.goldenaarcher.product.productservices.jar.path=/Users/usr/.m2/repository/com/goldenaarcher/product/productservices/1.0/productservices-1.0.jar
[echoproperties] org.springframework\:spring-core\:jar=/Users/usr/.m2/repository/org/springframework/spring-core/6.0.11/spring-core-6.0.11.jar
[echoproperties] ant.file=/Users/usr/study/maven/parent/productweb/pom.xml
[echoproperties] path.separator=\:
[echoproperties] os.version=13.5.2
[echoproperties] java.runtime.name=OpenJDK Runtime Environment
[echoproperties] java.vm.name=OpenJDK 64-Bit Server VM
[echoproperties] com.goldenaarcher.product\:productservices\:jar=/Users/usr/.m2/repository/com/goldenaarcher/product/productservices/1.0/productservices-1.0.jar
[echoproperties] ant.core.lib=/Users/usr/.m2/repository/org/apache/ant/ant/1.8.2/ant-1.8.2.jar
[echoproperties] java.vendor.url.bug=https\://github.com/microsoft/openjdk/issues
[echoproperties] user.dir=/Users/usr/study/maven/parent
[echoproperties] maven.dependency.org.junit.platform.junit-platform-engine.jar.path=/Users/usr/.m2/repository/org/junit/platform/junit-platform-engine/1.10.0/junit-platform-engine-1.10.0.jar
[echoproperties] os.arch=x86_64
[echoproperties] maven.multiModuleProjectDirectory=/Users/usr/study/maven/parent
[echoproperties] org.junit.platform\:junit-platform-commons\:jar=/Users/usr/.m2/repository/org/junit/platform/junit-platform-commons/1.10.0/junit-platform-commons-1.10.0.jar
[echoproperties] maven.dependency.org.opentest4j.opentest4j.jar.path=/Users/usr/.m2/repository/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar
[echoproperties] maven.dependency.org.apache.geronimo.specs.geronimo-servlet_3.0_spec.jar.path=/Users/usr/.m2/repository/org/apache/geronimo/specs/geronimo-servlet_3.0_spec/1.0/geronimo-servlet_3.0_spec-1.0.jar
[echoproperties] maven.dependency.org.springframework.spring-core.jar.path=/Users/usr/.m2/repository/org/springframework/spring-core/6.0.11/spring-core-6.0.11.jar
[echoproperties] org.springframework\:spring-context\:jar=/Users/usr/.m2/repository/org/springframework/spring-context/6.0.11/spring-context-6.0.11.jar
[echoproperties] maven.dependency.org.junit.jupiter.junit-jupiter-api.jar.path=/Users/usr/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.10.0/junit-jupiter-api-5.10.0.jar
[echoproperties] project.build.sourceDirectory=/Users/usr/study/maven/parent/productweb/src/main/java
[echoproperties] java.vm.info=mixed mode, sharing
[echoproperties] java.vm.version=17.0.8.1+1-LTS
[echoproperties] maven.dependency.org.springframework.spring-context.jar.path=/Users/usr/.m2/repository/org/springframework/spring-context/6.0.11/spring-context-6.0.11.jar
[echoproperties] maven.project.dependencies.versions=5.10.0\:1.10.0\:1.3.0\:1.10.0\:5.10.0\:1.1.2\:1.0\:1.0\:6.0.11\:6.0.11\:6.0.11\:6.0.11\:6.0.11\:6.0.11\:
[echoproperties] java.class.version=61.0
[echoproperties] ant.project.default-target=main
[echoproperties] maven.dependency.org.apiguardian.apiguardian-api.jar.path=/Users/usr/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for productparent 1.0:
[INFO]
[INFO] productparent ...................................... SUCCESS [  0.305 s]
[INFO] productservices .................................... SUCCESS [  0.074 s]
[INFO] productweb Maven Webapp ............................ SUCCESS [  0.048 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.510 s
[INFO] Finished at: 2023-09-20T21:02:03-04:00
[INFO] ------------------------------------------------------------------------

在这里插入图片描述

我这里应该只列出了一个项目(web)的属性……太长了,感觉拉不完……

这里主要就是提供了一些默认的 property 名称,如 project 相关信息,这个也可以在 POM 中直接使用。

下面的这个设定会直接用 artifactId 作为最终打包的名称:

<build>
	<finalName>${project.artifactId}</finalName>
</build>

在这里插入图片描述

这样在 build 之后,最终的 war 文件名就是 productweb.war

还有一些其他的用法,包括访问 project.build.directory 等,这些还是在要用的时候 google 一下比较方便

除此之外它还可以访问 java 的系统属性,以及手写的一些属性,如用过不少次的 maven.compiler.source

目前最新版本的一些用法如下:

		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>compile</id>
						<phase>compile</phase>
						<configuration>
							<target>
								<echo message="Project Name: ${project.name}" />
							</target>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>

它可以在命令行 echo 项目名称:

在这里插入图片描述

主要来说……用的不多就是了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1034579.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

成集云 | 用友T+集成聚水潭ERP(用友T+主管供应链)| 解决方案

源系统成集云目标系统 方案介绍 用友T是一款由用友畅捷通推出的新型互联网企业管理系统&#xff0c;它主要满足成长型小微企业对其灵活业务流程的管控需求&#xff0c;并重点解决往来业务管理、订单跟踪、资金、库存等管理难题。 聚水潭是一款以SaaS ERP为核心&#xff0c;集…

mysql事务测试

mysql的事务处理主要有两种方法1、用begin,rollback,commit来实现 begin; -- 开始一个事务 rollback; -- 事务回滚 commit; -- 事务提交 2、直接用set来改变mysql的自动提交模式 mysql默认是自动提交的&#xff0c;也就是你提交一个sql&#xff0c;它就直接执行&#xff01;我…

微信管理系统可以解决什么问题?

微信作为一款社交通讯软件&#xff0c;已经成为人们日常生活中不可缺少的工具。不仅个人&#xff0c;很多企业都用微信来联系客户、维护客户和营销&#xff0c;这自然而然就会有很多微信账号、手机也多&#xff0c;那管理起来就会带来很多的不便&#xff0c;而微信管理系统正好…

基于径向基神经RBF的空调功率预测,RBF神经网络的详细原理,RBF回归预测代码

目录 完整代码和数据下载链接&#xff1a;基于MATLAB的RBF的空调能耗预测_模糊空调matlab资源-CSDN文库 https://download.csdn.net/download/abc991835105/87833598 RBF的详细原理 RBF的定义 RBF理论 易错及常见问题 RBF应用实例&#xff0c;基于rbf的空调功率预测 代码 结果…

C语言大佬的必杀技---宏的高级用法

C语言大佬的必杀技—宏的高级用法 目录: 字符串化标记的拼接宏的嵌套替换多条语句防止一个文件被重复包含宏和函数的区别 可能大家在学习的时候用得比较少&#xff0c;但是在一些代码量比较大的时候&#xff0c;这样使用&#xff0c;可以大大的提高代码的可读性&#xff0c;…

minio报错should be less than or equal解决方案

minio报错should be less than or equal解决方案 问题背景解决方案Lyric&#xff1a; 当作你的请求 问题背景 在进行minio扩容时&#xff0c;报错 parity validation returned an error: parity 4 should be less than or equal to 2 <- (4, 4), for pool(2nd解决方案 mi…

ModbusTCP 转 Profinet 主站网关控制汇川伺服驱动器配置案例

ModbusTCP Client 通过 ModbusTCP 控制 Profinet 接口设备&#xff0c;Profinet 接口设备接入 DCS/工控机等 兴达易控ModbusTCP转Profinet主站网关&#xff08;XD-ETHPNM20&#xff09;采用数据映射方式进行工作。 使用设备&#xff1a;兴达易控ModbusTCP 转 Profinet 主站网关…

敏捷开发七大步骤和敏捷工具

敏捷开发是一种以人为核心、迭代、循序渐进的开发方法。在敏捷开发中&#xff0c;软件项目的构建被切分成多个子项目&#xff0c;各个子项目的成果都经过测试&#xff0c;具备集成和可运行的特征。敏捷开发并不追求前期完美的设计、完美编码&#xff0c;而是力求在很短的周期内…

2023-9-23 区间分组

题目链接&#xff1a;区间分组 #include <iostream> #include <algorithm> #include <queue>using namespace std;const int N 100010;struct Range {int l, r;bool operator< (const Range &W) const {return l < W.l;} }range[N];int main() {i…

一篇文章带你走进测试工程师的世界

【软件测试行业现状】2023年了你还敢学软件测试&#xff1f;未来已寄..测试人该何去何从&#xff1f;【自动化测试、测试开发、性能测试】 一、 测试工程师&#xff1a; 1、 国内定位和发展前景&#xff1a; 测试工程师&#xff0c;软件质量的把关者&#xff0c;工作起点高&…

Scala最基础入门教程

文章目录 一、简介1、概述2、Idea环境 二、变量和数据类型1、注释2、变量和常量&#xff08;重点&#xff09;3、标识符的命名规范4、关键字(39)5、字符串输出6、数据类型6.1 整数类型(Byte、Short、Int、Long)6.2 浮点类型&#xff08;Float、Double&#xff09;6.3 字符类型&…

量化交易97个Python库、696个策略、55本书合集

今天和大家分享一个超多内容的量化交易资料合集&#xff0c;包含了696个策略&#xff0c;55本书&#xff0c;97个库&#xff0c;目前还在不断更新&#xff0c;强烈推荐量化交易方向的同学收藏学习。 这个合集是由Edouard dArchimbaud、James Munro和GrimyFishTank三位大佬整理…

6.wifi开发【智能家居:下】,正式开发:智能开关灯,智能采集温湿度,智能调彩灯

一。WEB Server开发 1.需求分析 用户通过页面操作插座彩灯温湿度 【开发前端1】&#xff1a;智能插座网页设计 智能插座网页设计需求 1.通过浏览器访问ESP8266 webserver 2.显示“创客学院-WiFi-智能家居” 3.显示“智能插座” 4.显示当前插座工作状态 5.按键触发插座动作 2.…

【【萌新的FPGA学习之初识ZYNQ】】

萌新的FPGA学习之初识ZYNQ 进入 21 世纪&#xff0c;FPGA 的发展进入了累积阶段。人们发现&#xff0c;FPGA 的发展此时遭遇了瓶颈&#xff0c;因此单纯的 提升 FPGA 的容量已经不能满足各类应用的需求。由于更多客户开始追求更高的性价比&#xff0c;FPGA 不得不从 单纯的可编…

swift 天气

定义不同模式主题 自定义颜色 输入框 委托和协议 扩展 协议 http 请求 调用api 闭包

实现人工智能的去中心化,权力下放是最佳途径!

Web3和人工智能&#xff08;AI&#xff09;的交集&#xff0c;已成为加密社区中最热门的争论话题之一。毕竟&#xff0c;生成式AI正在彻底改变传统软件堆栈的所有领域&#xff0c;Web3也不例外。鉴于去中心化是Web3的核心价值主张&#xff0c;许多新兴的Web3生成AI项目和场景都…

统计回归模型中的一些概念解释

1、置信区间一般怎么算 置信区间是在统计学中用来估计总体参数的范围。一般来说&#xff0c;置信区间的计算依赖于样本数据的分布和样本量。以下是一种常用的计算置信区间的方法&#xff1a; 1. 首先确定置信水平&#xff08;confidence level&#xff09;&#xff0c;通常为9…

连接器公司介绍

连接器是模块之间的桥梁&#xff0c;在选型中考虑的因素较多。特别是在信号完整性领域&#xff0c;涉及到高速、射频方向需要全方位评估。记录几家全球连接器知名企业方便后续访问学习。 泰科连接器第一名 泰科电子TEConnectivity&#xff08;简称“TE”&#xff09;总部位于瑞…

高并发场景防止超卖的实现

一、商品秒杀-超卖 ApiOperation(value"秒杀实现方式——Lock加锁") PostMapping("/start/lock") public Result startLock(long skgId){try{log.info("来时秒杀方式一");final long userId (int)(new Random().nextDouble()*(99999-100001))1…

2023.9.23-最强实战:Typora+mkdocs构建自己的知识库博客

最强实战&#xff1a;Typoramkdocs构建自己的知识库&博客-2023.9.23 winodws-ecs-rsync-mkdocs-typora-百度网盘同步空间数据维护方案 目录 实验环境 win10 typora v1.7.4 mkdocs, version 1.5.2 vscode v1.82.2 阿里云轻量服务器实验软件 链接&#xff1a;https://pan.…