Gradle convert maven plugin

How can I write an equivalent maven plugin for the next gradle plugin?

/* * 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) } } } } } } 
+5
source share
1 answer

It really depends on what exactly you want to achieve.

If you want to help write the maven plugin in general, you need to read the documentation .

If you want to filter out the properties of the system that the Maven JVM switches to the test JVM, I see no other option than expanding the maven-surefire-plugin and adding an option for such a mapping there. (Note that by default, Maven passes all of its system properties to the test JVM.) This is definitely doable, but perhaps you can achieve your goal with what maven already offers.

You can definitely pass additional system properties to the test JVM from Maven using:

 <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> 

as described by http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html .

In this case, you can set the value of anotherProperty from the command line by calling maven

 mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty 

You can also use Surefire argline to pass multiple JVM properties. For instance,

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

and do maven as follows

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

in this case, you will see the properties foo and hello with the values bar and ahoy , respectively, in the test JVM.

+1
source

Source: https://habr.com/ru/post/1234687/


All Articles