将参数发送到maven插件

问题描述 投票:1回答:2

在我的pom文件中,我使用此配置执行构建插件。

我可以从插件代码中访问customProp吗?

<execution>
...
  <configuration>
    <configOptions>
      <additional-properties>useTags=true</additional-properties>
    </configOptions>
    <customProp>custom-value</customProp>
java maven maven-plugin spring-boot-maven-plugin
2个回答
1
投票

假设你正在开发插件......

对的,这是可能的。查看Parameters部分Maven的插件开发指南。

您必须在Mojo中定义一个属性:

@Parameter( property = "your-plugin.customProperty", defaultValue = "custom" )
private String customProperty;

1
投票

如果我理解正确,当您配置spring-boot-maven-plugin并构建应用程序时,您可以通过BuildProperties对象访问有关应用程序构建的信息,如 -

@Autowired
BuildProperties buildProperties;

并阅读像 -

// Artifact's name from the pom.xml file
buildProperties.getName();
// Artifact version
buildProperties.getVersion();

如果预定义的属性不够,您可以将自己的属性从pom.xml文件传递到BuildProperties

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>build-info</goal>
            </goals>
            <configuration>    
                <additionalProperties>                    
                      <java.version>${java.version}</java.version>                    
                      <some.custom.property>some value</some.custom.property>                
               </additionalProperties>            
            </configuration>        
     </execution>
    </executions>
</plugin>

您可以直接传递值,也可以使用<properties>pom.xml部分中定义的自定义属性,然后使用${property.name}占位符进行引用。

您可以通过调用buildProperties.get("property.name").来访问以这种方式定义的自定义属性

© www.soinside.com 2019 - 2024. All rights reserved.