栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在非JAR Maven项目之间共享公共资源

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在非JAR Maven项目之间共享公共资源

我已经出于类似的目的使用了maven-remote-resources-
plugin
。创建一个单独的类型为jar的资源项目(com.company:resourceProj)。将JMeter资源文件放入

/src/main/resources

/src/main/resources/common.properties  (your filenames obviously)/src/main/resources/a.propertiesetc.

按照示例中的说明创建捆绑包。

现在,将此配置添加到您的父POM(如果需要,在测试配置文件中):

<properties>  <shared.resources.dir>${project.build.directory}/shared-resources</shared.resources.dir></properties><plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-remote-resources-plugin</artifactId>  <executions>    <execution>      <id>load-resources</id>      <phase>initialize</phase>      <goals>        <goal>process</goal>      </goals>      <configuration>        <resourceBundles>          <resourceBundle>com.company:resourceProj:version</resourceBundle>        </resourceBundles>        <attached>false</attached>        <outputDirectory>${shared.resources.dir}</outputDirectory>      </configuration>    </execution>  </executions></plugin>

现在,告诉Maven这些是测试资源。如果您的测试资源元素在各个模块中是一致的,则也可以在父级中使用,如果它们不同,则可以在模块POM中使用。(根据我在子项目中定义的Maven
3资源的经验,其优先级高于父项目;它们不会合并。)

<testResources>    <testResource>      <directory>${shared.resources.dir}</directory>      <includes>         <include>common.properties</include>         <include>${module.file}.properties</include>      </includes>    </testResource>    <!-- any other test resources here -->  </testResources>

在子模块中,定义资源模块属性(这是模块a):

<properties>  <module.file>a</module.file></properties>

对此进行调整以满足您的用例。

-—编辑----

如果将配置放入父POM中,则取决于子级提供的配置,父POM可能无法构建。当我们构建共享的基础/父项目时,我们不想要求定义子项目(继承者)应提供的所有属性。因此,我们在构建共享项目时会激活此配置文件,以绕过仅适用于子项的所有内容。

为此,将一个空文件添加

pom-packaging.marker
到父项目的basedir。然后将此配置文件添加到父POM。构建父项目后,Maven将找到标记文件,启用概要文件,并禁用概要文件中包含的所有执行。构建子项目时,标记文件不存在,因此POM主要部分中的配置将生效。

我也将这种技术与Enforcer插件一起使用-
父级定义了强制规则,该规则应应用于从父级继承的项目,但是在构建时不能满足该规则。如果插件提供“跳过”属性,则可以在此配置文件中启用该属性,而不是在插件配置中使用phase
= none。

<profile>    <id>pom-packaging</id>    <activation>        <file> <exists>pom-packaging.marker</exists>        </file>    </activation>    <build>        <plugins> <plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-remote-resources-plugin</artifactId>     <executions>         <execution>      <id>load-resources</id>      <phase>none</phase>    <!-- disables this execution -->  </execution>         </executions>     </plugin>          ....  other plugin executions here ....         </plugins>    </build></profile>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/392149.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号