带扩展的Maven 3概要文件
我的问题已在中提出,但解释不清楚 我的一个pom.xml文件中有此生成定义:带扩展的Maven 3概要文件,maven,maven-3,build-process,maven-profiles,maven-extension,Maven,Maven 3,Build Process,Maven Profiles,Maven Extension,我的问题已在中提出,但解释不清楚 我的一个pom.xml文件中有此生成定义: <build> <finalName>${my.project}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>mav
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
问题那么使用扩展标签意味着我不能使用配置文件?如何通过概要文件使用或更改构建扩展?这是一个疯狂的想法:使用模块 定义父级
pom
,如下所示:
<groupId>org.example</groupId>
<artifactId>my-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>use-pom1</id>
<modules>
<module>pom1</module>
</modules>
</profile>
<profile>
<id>use-pom2</id>
<modules>
<module>pom2</module>
</modules>
</profile>
</profiles>
org.example
我的父母
1
聚甲醛
use-pom1
pom1
use-pom2
聚甲醛
在pom1
和pom2
上定义所需的扩展。事实上,这位官员并不清楚extensions
作为Maven配置文件的一部分的可能用法,因为它声明可以在其中包含build
元素,但不清楚build
部分的内容
但是,官方会有效地过滤并提供您在配置文件
部分中实际可以使用的构建
部分。实际上,扩展
并不存在
然而,什么是Maven扩展?构建/生命周期增强,但也(本质上):一个库添加到Maven构建的运行时类路径中,它参与构建,但不与最终工件打包
因此,在这种情况下(如果您需要在概要文件中有扩展,或者需要一个概要文件来更改/添加扩展),您可以使用以下技巧:
- 拥有一个无害的扩展作为构建的默认扩展(其中无害意味着任何可以作为构建类路径一部分的库,并且本质上根本不会影响它)
- 具有定义此扩展的GAV坐标(GroupId,ArtifactId,Vversion)的属性
- 具有使用所需(有用)扩展名覆盖这些特性的配置文件
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.11</extension.version>
</properties>
<build>
<extensions>
<extension>
<groupId>${extension.groupId}</groupId>
<artifactId>${extension.artifactId}</artifactId>
<version>${extension.version}</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>customize-extension</id>
<properties>
<extension.groupId>junit</extension.groupId>
<extension.artifactId>junit</extension.artifactId>
<extension.version>4.12</extension.version>
</properties>
</profile>
</profiles>
</project>
并作为生成日志的一部分进行检查:
[DEBUG] Populating class realm extension>junit:junit:4.11
[DEBUG] Included: junit:junit:jar:4.11
现在,让我们使用我们的技巧:通过配置文件添加(更改)构建扩展:
<profiles>
<profile>
<id>local-build</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<finalName>${my.project}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.1.19</version>
</extension>
</extensions>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/settings.properties</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
mvn initialize -X -Pcustomize-extension
作为构建日志的一部分,我们将:
[DEBUG] Populating class realm extension>junit:junit:4.12
[DEBUG] Included: junit:junit:jar:4.12
宾果。Maven选择了一个不同的扩展(在本例中是一个不同的版本,
4.12
),我们成功地通过概要文件更改(或实际添加了一个有意义的)构建扩展 我认为解决办法就在这里
定义定义扩展的构建部分,然后在概要文件中设置属性true(如下面所示的第二个概要文件)
org.apache.maven.wagen
马车ssh
2.9
创建默认值
真的
建造
满的
org.springframework.boot
springbootmaven插件
重新包装
创建核心
建造
满的
org.apache.maven.plugins
maven jar插件
真的
2.6
导入站点核心-${project.version}
做罐子
包裹
罐子
这的确是一个有趣的想法,但可能会使事情复杂化。由于这是一个有利害关系的生产系统,我正试图找到一个更简单\稳定\官方\经过测试的解决方案。多亏了Thoughell,您可以尝试使用descriptor.xml使用maven assembly plugin
。但是我怀疑它会像扩展那样起作用。这里你所说的“然后在配置文件中设置属性true(如下面显示的第二个配置文件中所示)”是什么意思?你能在第二个配置文件中指定你在这里谈论的标记名吗?这会有帮助的。或者,如果我只是在概要文件之外保留一个构建,并且不在概要文件中添加任何特定的内容(不设置任何属性),它会工作吗?谢谢
mvn initialize -X -Pcustomize-extension
[DEBUG] Populating class realm extension>junit:junit:4.12
[DEBUG] Included: junit:junit:jar:4.12
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.9</version>
</extension>
</extensions>
</build>
<profiles>
<profile>
<id>create-default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>create-core</id>
<activation>
<property>
<name>build</name>
<value>full</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<extensions>true</extensions>
<version>2.6</version>
<configuration>
<finalName>import-station-core-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>