1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
我無法直接編輯 pom.xml 的<屬性>/<屬性>部分中已存在的任何屬性。
但是,我想出的答案是使用插件運(yùn)行shell腳本,編輯輸出,并將其保存到稍后可以在文件中使用的變量中。請注意,除了插件部分之外,他的變量實(shí)際上并沒有在文件中的任何地方定義。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>
然后,元數(shù)據(jù)部分使用該變量,如下所示:
<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>
添加回答
舉報(bào)