是否可以在运行时在属性中获取Maven依赖关系? [英] Is it possible to get Maven dependencies in a property at run-time?
问题描述
我正在处理一种情况,即我们在POM中使用LATEST和RELEASE关键字来获得某种依赖关系(依赖关系和项目均归我们所有,因此我们控制什么是LATEST和RELEASE ...并且我们一次仅支持一个版本).使用这些关键字使我们可以最大程度地减少发布后所需的维护.
I'm working with a situation where we are using the LATEST and RELEASE keywords in our POM for a certain dependency (both the dependency and the project are owned by us, so we control what is LATEST and RELEASE...and we only support one version at a time). Using these keywords allows us to minimize maintenance needed after a release.
在构建过程中有一个步骤,必须从解压后的依赖项中复制DLL,但是由于我们未指定特定版本,因此我们对解压后的依赖项的版本号进行了硬编码,并且每次发行后都必须对其进行更新.有没有办法在运行时从Maven属性获取此依赖项的版本?
There is a step in the build process that must copy DLLs from the unpacked dependency, but since we don't specify a specific version we have the version number of the unpacked dependency hard-coded and have to update it after every release. Is there a way get the version of this dependency at run-time from a Maven property?
maven-dependency-plugin(http://maven.apache.org/plugins/maven-dependency-plugin/index.html)的属性目标获取工件在本地存储库中的位置(不是我在寻找什么). depends-maven-plugin(如下所示: http://team.ops4j.org/wiki/display/paxexam/Pax+Exam+-+Tutorial+1 )可以生成一个包含各种依赖项及其版本的文件,但要使用该文件,需要一个过程来读取该文件并利用这些信息.我想知道是否还有更多的行家之道",例如访问依赖版本的属性.
The properties goal of the maven-dependency-plugin (http://maven.apache.org/plugins/maven-dependency-plugin/index.html) gets the location of the artifact in the local repository (which is not what I'm looking for). The depends-maven-plugin (shown here: http://team.ops4j.org/wiki/display/paxexam/Pax+Exam+-+Tutorial+1) can generate a file that contains the various dependencies and their versions, but using that would require having a process read the file and utilize that information. I'm wondering if there is a more "Maven way", such as accessing a property for the dependency version.
为了澄清起见,我们需要版本号,以便我们可以进入解压后的依赖关系目录来复制文件.
For clarification, we need the version number so we can get to the directory of the unpacked dependency to copy files.
推荐答案
我不确定您对行家方式"的意思,但在查看了您已经提到的相同插件后,我做了类似的事情:
I'm not sure what you mean with 'maven way' but I did something like this after looking at the same plugins you already mention:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.properties.put('firstdependencyinthepom', project.dependencies[0]['version'])
project.properties.put('seconddependencyinthepom', project.dependencies[1]['version'])
</source>
</configuration>
</execution>
</executions>
</plugin>
然后我可以分别使用$ {firstdependencyinthepom}和$ {seconddependencyinthepom}来引用这些依赖项的版本.
and then I was able to refer to versions of these dependencies with ${firstdependencyinthepom} and ${seconddependencyinthepom} respectively.
这篇关于是否可以在运行时在属性中获取Maven依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!