Java gradle到maven插件转换

Java gradle到maven插件转换,java,maven,gradle,Java,Maven,Gradle,如何为下面定义的gradle插件编写等效的maven插件 /* *将系统属性从gradle JVM复制到测试JVM的插件 *代码是从gradle讨论区复制的: * http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task */ 类SystemPropertiesMappingPlugin实现插件{ 公开作废申请(项目){ project.tasks.withType(Test){testTask

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

/*
*将系统属性从gradle JVM复制到测试JVM的插件
*代码是从gradle讨论区复制的:
* http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task
*/  
类SystemPropertiesMappingPlugin实现插件{
公开作废申请(项目){
project.tasks.withType(Test){testTask->
testTask.ext.mappedSystemProperties=[]
doFirst{
mappedSystemProperties.each{mappedPropertyKey->
def systemPropertyValue=System.getProperty(mappedPropertyKey)
如果(systemPropertyValue){
systemProperty(mappedPropertyKey,systemPropertyValue)
}  
}  
}  
}  
}  
}

这实际上取决于你到底想要实现什么

如果你想帮助编写一个maven插件,你必须这样做

如果您想过滤Maven JVM传递给测试JVM的系统属性,我看不到任何其他选项,除了扩展
Maven surefire插件
插件并在那里添加一个选项来进行这种映射。(请注意,默认情况下,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>
您还可以使用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>

在本例中,您将在测试JVM中分别看到属性
foo
hello
,它们的值分别为
bar
ahoy

您想将java插件转换为maven,对吗。。我可以在maven pom中使用它作为插件。好的,如果我错了,请纠正我,解释我你想怎么做,你想在哪个ide中做这件事,我正在使用Eclispe ide,在我的一个项目的build.gradle中有以下代码,用于运行jive测试用例。现在我需要为build.gradle生成一个Maven pom.xml文件,我需要将该插件转换为Maven plugin您想从build.gradle生成poim.xml吗?您好。。关于这个问题,我有以下需要映射的属性:mappedSystemProperties=['jivetests','jive.suite.name','jive.package.base','jive.package.include','jive.package.exclude','jive.testclass.exclude','jive.testclass.id.include','jive.testclass.id.exclude'。。。。那么,如何在pom.xml中获取特定属性名称的属性值(因为System.getProperty在这里没有帮助)?
<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"