0

How to display maven properties in Eclipse?

The pom below, based on antrun plugin is not work:

<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>Test_DisplayMavenVariables</groupId>
    <artifactId>Test_DisplayMavenVariables</artifactId>
    <version>0.0.1-SNAPSHOT</version>


    <properties>
        <testproperty>This is a test property</testproperty>
    </properties>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <echo>Displaying value of 'testproperty' property</echo>
                                    <echo>[testproperty] ${testproperty}</echo>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

UPDATE

If ran to goal "validate", the output is following:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Test_DisplayMavenVariables 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.110s
[INFO] Finished at: Sun Mar 23 15:22:00 MSK 2014
[INFO] Final Memory: 4M/183M
[INFO] ------------------------------------------------------------------------
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

1

You have put the antrun definition inside a pluginManagement block.

pluginManagement means: "if someone uses this plugin, he will do it in the following way..."

In your example, no one uses the plugin, since there is no normal plugin definition. Remove <pluginManagement> and </pluginManagement> from your pom, and it will work.

blackbuild
  • 5,026
  • 1
  • 23
  • 35
  • Have you tried this? If I remove `pluginManagement` then I have error "Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.1:run (execution: default, phase: validate)" which I was found solvation here http://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin – Suzan Cioc Mar 23 '14 at 13:17
  • These are two separate issues. Your properties should be shown correctly. By the way: The accepted answer of your link is wrong. The second answer by Andrew White is correct. You achieve that easily by using the provided Quick Fix. – blackbuild Mar 23 '14 at 13:39
  • For Quickfix: right click the error, choose Quick Fix and select "Permanently mark goal run in pom.xml as ignored in Eclipse build". – blackbuild Mar 23 '14 at 13:47