Showing posts with label maven-plugin. Show all posts
Showing posts with label maven-plugin. Show all posts

Wednesday, December 28, 2016

internal maven properties

This page extracts a few classical values:
  • ${project.basedir} 
    • This references to the root folder of the module/project (the location where the current pom.xml file is located)
POM properties referencing useful build locations, with default values defined in the Super POM:
  • ${project.build.directory}
    • This represents by default the target folder.
  • ${project.build.outputDirectory}
    • This represents by default the target/classes folder.
  • ${project.build.testOutputDirectory}
    • This represents by default the target/test-classes folder.
  • ${project.build.sourceDirectory}
    • This represents by default the src/main/java folder.
  • ${project.build.testSourceDirectory}
    • This represents by default the src/test/java folder.
You can use further properties like the following:
  • ${project.build.finalName}
    • This is by default defined as ${project.artifactId}-${project.version}.
  • ${project.version}
    • This can be used at locations where you have to write a literal version otherwise, in particular if you are in a multi-modules build for inter modules dependencies.
User Settings
The settings.xml elements could be referenced by using things like this (see also at the Super POM):
  • ${settings.localRepository}
    • which references the location of the local repository. This is by default ${home}/.m2/repository.
Values are evaluated in sequence from different syntaxes:
valueevaluation resultcommon examples
project.*
pom.* (deprecated)
* (deprecated)
POM content (see POM reference)${project.version}
${project.build.finalName}
${project.artifactId}
${project.build.directory}
project.basedir
pom.basedir (deprecated)
basedir (deprecated)
the directory containing the pom.xml file${project.basedir}
project.baseUri
pom.baseUri (deprecated)
the directory containing the pom.xml file as URI${project.baseUri}
build.timestamp
maven.build.timestamp
the UTC timestamp of build start, in yyyy-MM-dd'T'HH:mm:ss'Z' default format, which can be overridden with maven.build.timestamp.format POM property${maven.build.timestamp}
*user properties, set from CLI with -Dproperty=value${skipTests}
*model properties, such as project properties set in the pom${any.key}
maven.homeThe path to the current Maven home.${maven.home}
maven.versionThe version number of the current Maven execution (since 3.0.4). For example, "3.0.5".${maven.version}
maven.build.versionThe full build version of the current Maven execution (since 3.0.4). For example, "Apache Maven 3.2.2 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19T14:51:28+01:00)".${maven.build.version}
*Java system properties (see JDK reference)${user.home}
${java.home}
env.*
*
environment variables${env.PATH}
settings.*Local user settings (see settings reference)${settings.localRepository}

Wednesday, April 10, 2013

Ant Mojo Debuging: turning on ant-tasks logging from a maven-plugin or command line.

Here you have a legacy ant build.xml that you would like to integrate as an Ant Mojo (which is not the same as the antrun-plugin). How can we switch on the debugging from maven on the ant side... following the tutorial we create a hello ant execution... and this results in the hello.build.xml and hello.mojos.xml. Next we skip to the "Built It! Run It!" section and change the following to our projects pom.xml that is using the hello plugin.
$ mvn org.myproject.plugins:hello-plugin:hello
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.410s
[INFO] Finished at: Wed Apr 10 09:53:12 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Now change the call and add -DantMessageLevel=[info|debug|trace].
$ mvn org.myproject.plugins:hello-plugin:hello -DantMessageLevel=debug
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---
Project base dir set to: /Users/tmp
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml with URI = file:///var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Setting ro project property: ant.file.null -> /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Project base dir set to: /Users/akaan/tmp
 +Target: 
 +Target: hello
Adding reference: project
Adding reference: session
Adding reference: mojoExecution
Setting ro project property: messageLevel -> debug
Setting ro project property: basedir -> /Users/tmp
Build sequence for target(s) `hello' is [hello]
Complete build sequence is [hello, ]

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.413s
[INFO] Finished at: Wed Apr 10 09:55:09 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Or if you need to pass the configuration item in the plugin definition itself use messageLevel.
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.myproject.tests</groupId>
  <artifactId>hello-plugin-tests</artifactId>
  <version>1.0</version>
  
  <name>Test Project</name>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.myproject.plugins</groupId>
        <artifactId>hello-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        
        <configuration>
          <name>John</name>


          <messageLevel>debug</messageLevel> 


        </configuration>
        
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>one</goal>
              <goal>two</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>