2015-10-28 57 views
5

如何为以下定义的gradle插件编写等价的maven插件?gradle to 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) 
        } 
       } 
      } 
     } 
    } 
} 
+0

你想将java插件转换为maven吗? –

+0

是啊..我可以在maven pom中使用它作为插件。 –

+0

Okz尝试http://crunchify.com/how-to-convert-existing-java-project-to-maven-in-eclipse/如果我错了,请纠正我与解释我如何做到这一点imean in你想要做的这个IDE –

回答

1

这真的取决于你想要达到的目标。

如果您想帮助编写一般的maven插件,您需要登录read the documentation

如果你想过滤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

在这种情况下,你可以通过调用行家

mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty 

您还可以使用神火argline到多个属性传递到JVM设置的anotherProperty命令行的值。例如

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

和执行行家如下

mvn test -DpropertiesIWantToSetFromMvnCommandLine="-Dfoo=bar -Dhello=ahoy" 
在这种情况下

,你会看到性能foohello与值分别为barahoy,在您的测试JVM。

+0

你好..关于这个问题,我有以下需要映射的属性:mappedSystemProperties = ['jivetests','jive.suite.name','jive.package.base','jive.package.include' ,'jive.package.exclude','jive.testclass.include','jive.testclass.exclude', 'jive.testclass.id.include','jive.testclass.id.exclude'] ....那么如何获得pom.xml中特定属性名称的属性值(因为System.getProperty在这里不起作用)? –