get IP address with maven and groovy

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>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(); … Continue reading get IP address with maven and groovy

Advertisements