<project xmlns=”http://maven.apache.org/POM/4.0.0&#8243; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”&gt;
<modelVersion>4.0.0</modelVersion>
<groupId>example.maven.groovy</groupId>
<artifactId>groovy-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>groovy-test</name>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>get-local-ip</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<classpath>
<element>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</element>
</classpath>
<source>
def addr = InetAddress.getLocalHost();
java.net.InetAddress[] addresses=InetAddress.getAllByName(addr.getHostName());
for (address in addresses) {
if (!(address.getHostAddress().startsWith(“0”))) {
println “Your IP address is: ”
println address;
project.properties.localIP=address.getHostAddress();
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

the output should contain something like:

Your IP address is:
my-computer-name12345/123.123.123.123

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s