繁体   English   中英

gradle to maven插件转换

[英]gradle to maven plugin conversion

如何为定义的以下gradle插件编写等效的maven插件?

/*
* Plugin to copy system properties from gradle JVM to testing JVM  
* Code was copied from gradle discussion froum:  
* http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task
*/  
class SystemPropertiesMappingPlugin implements Plugin{  
    public void apply(Project project){  
        project.tasks.withType(Test){ testTask ->  
            testTask.ext.mappedSystemProperties = []  
            doFirst{  
                mappedSystemProperties.each{mappedPropertyKey ->  
                    def systemPropertyValue = System.getProperty(mappedPropertyKey)  
                    if(systemPropertyValue){  
                        testTask.systemProperty(mappedPropertyKey, systemPropertyValue)  
                    }  
                }  
            }  
        }  
    }  
}

这实际上取决于你想要达到的目标。

如果你想帮助编写一般的maven插件,你必须阅读文档

如果你想过滤Maven JVM传递给你的测试JVM的系统属性,我没有看到任何其他选项,除了扩展maven-surefire-plugin插件并添加一个选项来进行这样的映射。 (请注意,默认情况下,Maven将其所有系统属性传递给测试JVM。)这绝对可行,但也许您可以通过maven已经提供的东西实现您的目标。

您可以使用以下方法将其他系统属性从Maven传递到测试JVM:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.19</version>
     <configuration>
         <systemPropertyVariables>
              <propertyName>propertyValue</propertyName>
              <anotherProperty>${myMavenProperty}</buildDirectory>
         </systemPropertyVariables>
     </configuration>
</plugin>

http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html所述

在这种情况下,您可以通过调用maven从命令行设置anotherProperty的值

mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty

您还可以使用Surefire argline将多个属性传递给JVM。 例如

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.19</version>
     <configuration>
         <argLine>${propertiesIWantToSetFromMvnCommandLine}</argLine>
     </configuration>
</plugin>

并按如下方式执行maven

mvn test -DpropertiesIWantToSetFromMvnCommandLine="-Dfoo=bar -Dhello=ahoy"

在这种情况下,您将在测试JVM中分别看到值为barahoy属性foohello

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM