java - Add groovy library in mvn project -
java - Add groovy library in mvn project -
i'm new groovy , i'm trying write simple project using groovy language. able write hello world script, deploy mvn artifact , execute it. i'm going beyond right , need import external libraries testing matters don't know how that.
i appreciate if give me tips this.
thanks!
you can specify dependencies project have test
scope, in case not used in compile
scope, or can specify dependencies used in scenarios (if, example, want write groovy tests without requiring rest of team so).
this sample pom.xml
has custom profile
element describes dependencies , executions run if current environment user "andylopresto". means if team doesn't want utilize groovy in build, still write test classes in groovy , have them run part of standard mvn test
phase on machine only. in team members' local machines (or shared jenkins instance), groovy test files ignored (not compiled or run, , groovy-all
dependency not downloaded onto machine).
example:
<?xml version="1.0" encoding="utf-8"?> <project xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://maven.apache.org/pom/4.0.0" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>your.package</groupid> <artifactid>artifact</artifactid> <version>0.0.1-snapshot</version> <packaging>pom</packaging> <developers> <developer> <id>alopresto</id> <name>andy lopresto</name> <email>alopresto@example.com</email> <roles> <role>developer</role> <role>owner</role> </roles> </developer> <developer> <id>jjava</id> <name>johnny java</name> <email>ihategroovy@example.com</email> <roles> <role>sticking older languages</role> </roles> </developer> </developers> <dependencymanagement> <dependencies> <!-- dependency available project code --> <dependency> <groupid>commons-codec</groupid> <artifactid>commons-codec</artifactid> <version>1.9</version> </dependency> <!-- dependency available during test phase --> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.11</version> <scope>test</scope> </dependency> <!-- dependency expected provided outside of maven --> <dependency> <groupid>org.apache.tomcat</groupid> <artifactid>tomcat-util</artifactid> <version>8.0.8</version> <scope>provided</scope> </dependency> </dependencies> </dependencymanagement> <profiles> <profile> <!-- custom profile groovy tests used on andy's computer --> <id>andylocaltest</id> <activation> <property> <name>env.user</name> <value>andylopresto</value> </property> </activation> <dependencies> <dependency> <groupid>org.codehaus.groovy</groupid> <artifactid>groovy-all</artifactid> <version>2.2.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>build-helper-maven-plugin</artifactid> <version>1.8</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/groovy</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <compilerid>groovy-eclipse-compiler</compilerid> <source>1.6</source> <target>1.6</target> <includes> <include>**/*.java</include> <include>**/*.groovy</include> </includes> </configuration> <dependencies> <dependency> <groupid>org.codehaus.groovy</groupid> <artifactid>groovy-eclipse-compiler</artifactid> <version>2.8.0-01</version> </dependency> <dependency> <groupid>org.codehaus.groovy</groupid> <artifactid>groovy-eclipse-batch</artifactid> <version>2.1.5-03</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles>
java maven groovy
Comments
Post a Comment