How to add a computed property to a Maven project using a plugin?

I wrote a Maven plugin to capture the IP address of a machine and would like to be able to create a property so that the IP address is filtered into a file (via $ {ipaddress}) when the archetype is generated.

I could not find how to do this. Somebody knows?

+3
source share
3 answers

properties-maven-plugin reads properties from a file and makes them available for assembly, as if they were defined in a string.

ip , , , .

MavenProject .

+1

org.codehaus.groovy.maven, IP- . IP- localIP, , maven, .. ${localIP}.

                 <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>
                              java.net.InetAddress address=InetAddress.getByName("${env.COMPUTERNAME}");
                              project.properties.localIP=address.getHostAddress();
                          </source>
                        </configuration>
                      </execution>
                    </executions>
                </plugin>
+1

, , , . , , , :) , - script, , , mvn build ( )

0
source

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


All Articles