1 回答
TA贡献1856条经验 获得超5个赞
我无法直接编辑 pom.xml 的<属性>/<属性>部分中已存在的任何属性。
但是,我想出的答案是使用插件运行shell脚本,编辑输出,并将其保存到稍后可以在文件中使用的变量中。请注意,除了插件部分之外,他的变量实际上并没有在文件中的任何地方定义。org.codehaus.gmaven.gmaven-pluginpom.xmlorg.codehaus.gmaven.gmaven-plugin
(将空变量放在 pom 的<属性>/<属性>部分中.xml始终会使变量为空。)
我像这样使用插件:org.codehaus.gmaven.gmaven-plugin
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<script>docker image inspect ${project.docker.image}:${project.version} --format='{{.Size}}</script>
</properties>
<source>
def command = project.properties.script
def process = command.execute()
process.waitFor()
def text = process.in.text.trim()
// Remove single quotes that surround number output
def number = text.substring(1, text.length()-1);
project.properties.dockerImageSize = number
</source>
</configuration>
</execution>
</executions>
</plugin>
然后,元数据部分使用该变量,如下所示:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<instructions>
<Bundle-Category>Thing</Bundle-Category>
<Bundle-Activator>com.company.thing.impl.Activator</Bundle-Activator>
<Bundle-Vendor>${company.vendor}</Bundle-Vendor>
<Bundle-ContactAddress>${company.contactAddress}</Bundle-ContactAddress>
<Bundle-Copyright>${company.copyright}</Bundle-Copyright>
<Bundle-LicenseType>${company.licenseType}</Bundle-LicenseType>
<Bundle-Description>${company.description}</Bundle-Description>
<Bundle-DockerImageSize>${dockerImageSize}</Bundle-DockerImageSize>
<Import-Package>
com.company.thing.api*;version="[0.0.10,1.0.0)",
*
</Import-Package>
</instructions>
</configuration>
</plugin>
添加回答
举报