Maven2 Binding to a custom Phase - java

I have a custom plugin that is defined using the pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pram.plugintest</groupId>
<artifactId>pram.plugintest</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1-SNAPSHOT</version>
<name>pram.plugintest Maven Mojo</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
<configuration>
<goalPrefix>blah</goalPrefix>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Running
mvn blah:touch
Creates a text file in the target directory as expected. I now create a lifecycles.xml file in the resources directory specified in the pom
<lifecycles>
<lifecycle>
<id>touch</id>
<phases>
<phase>
<id>package</id>
<executions>
<execution>
<goals>
<goal>touch</goal>
</goals>
</execution>
</executions>
</phase>
</phases>
</lifecycle>
</lifecycles>
In another maven project, I would like to bind the running of mvn blah:touch to an execution task similar to this
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>test1</id>
<phase>blah:touch</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
...
However running this creates the text file but doesn't attempt to run org.sonatype.mavenbook.weather.Main
Is this the correct approach?
Ultimately what I would like is to have multiple execution sections in the exec-maven-plugin that are not bound to the default phases. Logically it would look like this
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>test1</id>
<phase>blah:touch</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
</configuration>
</execution>
<execution>
<id>test2</id>
<phase>blah:touch2</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.SomeOtherClass</mainClass>
</configuration>
</execution>
</executions>
</plugin>
...
So if I run mvn blah:touch then org.sonatype.mavenbook.weather.Main will be executed and if I run mvn blah:touch2 then org.sonatype.mavenbook.weather.SomeOtherClass will be executed instead.
It seems like it should be straightforward to do but there's nothing in the documentation that seems to point out how to do this.

You can not use the exec-maven-plugin for this and you do not need the lifecycle.xml if you only would like to execute your plugin during a build.
To execute your plugin during a specific Maven phase, you simply have to add
<plugins>
<plugin>
<groupId>your.group.id</groupId>
<artifactId>your.artifact.id</artifactId>
<executions>
<execution>
<id>unique-execution-id</id>
<goals>
<goal>the.goal.of.your.plugin</goal>
</goals>
<phase>maven.phase</phase>
<configuration>
....
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Please specify the goal in the goal element without the prefix.
Did you read http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html?

Related

How to add a scala dependency to a Java project in intelliJ that use maven

I want to use a scala dependency in a pure Java project. There is no need to write scala in my project but of course I will have to use classes/etc defined in the scala project that I add as a dependency. Want to do this in a intelliJ maven project.
My pom looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.xxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>group ID</groupId>
<artifactId>scala dependancy</artifactId>
</dependency>
</dependencies>
</project>
Although I dont see any errors in pom, intellij is unable to import packages defined in the scala library. Essentially it cant find them.
What am I doing wrong here?
You can do so by adding the following dependency to your pom.xml file:
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag.
You have to set name of class with entry point to program ('main' method) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ScalaRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Take a look at this for more information.

How to exclude and include properly classes, packages and jar classes, lib from the jacoco report (Instrumentation offline)

I am using JaCoCo code coverage, but the report is including classes from jar, lib. (Offline Instrumentation, Maven)
I solved the problem with the offline configuration since "aspectj-maven-plugin" was changing the class files, and also now I successfully exclude the packages outside of target/classes -> src. thanks to this answer in stackoverflow.
But now I am getting the classes from jar, lib inside the report and I have not idea how to exclude then. I Show my configuration and examples below
I also tried this solution Exclude classes of jar files from jacoco coverage report But it doesn't work for me.
<exclude>**/lib/*</exclude>
My jacoco offline configuration:
<properties>
<jacoco.version>0.8.4</jacoco.version>
<argLine></argLine>
</properties>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
</dependency>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects all goals -->
<excludes>
<exclude>*</exclude>
<exclude>com/company/rrPackage/**/*.class</exclude>
<exclude>org/**/*.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
surefire-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<testNGArtifactName>...</testNGArtifactName>
<suiteXmlFiles>
<suiteXmlFile>...</suiteXmlFile>
</suiteXmlFiles>
<skip>${skip.test}</skip>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<properties>
...
</properties>
</configuration>
</plugin>
And the reason what I think that I am getting classes from jar inside de jacoco:report. In my pom.xml I have the following dependencies:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
Also I have a couple of import in my classes like this
import org.hsqldb.lib.StringUtil;
for example:
This has no dependency on the pom.xml but is used in one of the project classes, and jacoco shows it in the report
import javax.mail.internet.AddressException;
I have other cases with the same behavior that result in the same problem: Jacoco show those classes from jar in the report, as shown in the images
Try includes instead of excludes. Notice that you need .class at the end.
try something like that:
<configuration>
<includes>
<include>com/company/package/**/*.class</include>
</includes>
</configuration>
Base on your example:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects all goals -->
<includes>
<include>com/company/packageToInclude/**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
I don't know how you generate lib directory, because you don't provide complete example.
However in case of the following example
src/main/java/Example.java
class Example {
}
src/test/java/ExampleTest.java
public class ExampleTest {
#org.junit.Test
public void test() {
new Example();
}
}
and pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<jacoco.version>0.8.4</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>junit</includeArtifactIds>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
execution of mvn clean verify produces
$ ls -R target/classes
target/classes:
Example.class lib
target/classes/lib:
junit-4.12.jar
and following report
And after addition of following <configuration>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>instrument</goal>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>lib/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
execution of the same command mvn clean verify produces following report
If the above doesn't help, then please provide absolutely complete example allowing everybody else to reproduce exactly the same what you do.

Using git-commit-id-plugin in maven works in package-phase but not in install-phase

I'm using the git-commit-id-plugin (see https://github.com/ktoso/maven-git-commit-id-plugin). It packages correctly when I'm setting up an annotated tag like e.g. v1.0.0, meaning the target-directory has a jar file named deploy-test-Test-v1.0.0.jar.
The problem is, that the maven install phase creates the following files in my local .m2-directory:
Test-${git.closest.tag.name}
|- deploy-test-Test-${git.closest.tag.name}.jar
|- deploy-test-Test-${git.closest.tag.name}.pom
|- _remote.repositories
I've tested this with the example pom.xml.
What can I do to get the same name (deploy-test-Test-v1.0.0.jar)?
<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>com.mytest</groupId>
<artifactId>deploy-test</artifactId>
<packaging>jar</packaging>
<version>Test-${git.closest.tag.name}</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>Test-${git.closest.tag.name}</revision>
</properties>
<dependencies/>
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<!-- *NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here -->
<phase>package</phase>
</execution>
</executions>
<configuration>
<!-- If you'd like to tell the plugin where your .git directory is, use this setting, otherwise we'll perform a search trying to figure out the right directory. It's better to add it explicitly IMHO. -->
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<dateFormatTimeZone>${user.timezone}</dateFormatTimeZone>
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<format>properties</format>
<skipPoms>true</skipPoms>
<injectAllReactorProjects>false</injectAllReactorProjects>
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo>
<skip>false</skip>
<runOnlyOnce>false</runOnlyOnce>
<useNativeGit>false</useNativeGit>
<abbrevLength>7</abbrevLength>
<commitIdGenerationMode>flat</commitIdGenerationMode>
<gitDescribe>
<skip>false</skip>
<always>false</always>
<abbrev>7</abbrev>
<dirty>-dirty</dirty>
<match>*</match>
<tags>false</tags>
<forceLongFormat>false</forceLongFormat>
</gitDescribe>
<validationProperties>
<validationProperty>
<name>validating project version</name>
<value>${project.version}</value>
<shouldMatchTo>
<![CDATA[^.*(?<!-SNAPSHOT)$]]>
</shouldMatchTo>
</validationProperty>
</validationProperties>
<validationShouldFailIfNoMatch>true</validationShouldFailIfNoMatch>
<evaluateOnCommit>HEAD</evaluateOnCommit>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
To incorporate git-commit-id plugin into the version number for the entire maven build cycle (till deploy)
<properties>
<java.version>1.8</java.version>
<snapshot.string>-SNAPSHOT</snapshot.string>
<!-- Snapshot Version Number -->
<!-- <version.number>${git.commit.time}.${git.commit.id.abbrev}${s`enter code here`napshot.string}</version.number> -->
<!-- Release Version Number -->
<version.number>${git.commit.time}.${git.commit.id.abbrev}</version.number>
<release.repo.key>libs-release-local</release.repo.key>
<snapshot.repo.key>libs-snapshot-local</snapshot.repo.key>
<artifactory.url>http://xxx.xxx.x.xxx:yyyy/artifactory</artifactory.url>
<release.repository.url>${artifactory.url}/${release.repo.key}</release.repository.url>
<snapshot.repository.url>${artifactory.url}/${snapshot.repo.key}</snapshot.repository.url>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dateFormat>yyyyMMdd.HHmmss</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile>
<injectAllReactorProjects>true</injectAllReactorProjects>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>change-version</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>
< ![CDATA[
import org.apache.maven.artifact.versioning.VersionRange; git_revision = '${version.number}'
if (!project.properties['revision'] ? .trim()) {
println 'Change `version` to ' + git_revision
System.properties['revision'] = git_revision
project.properties['revision'] = git_revision
project.properties['project.version'] = git_revision
project.properties['git.build.version'] = git_revision
project.version = git_revision
project.artifact.version = git_revision
project.artifact.versionRange = VersionRange.createFromVersion(git_revision)
}
]] >
</script>
</scripts>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.14</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>release</id>
<name>local-releases</name>
<url>${release.repository.url}</url>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>snapshots</id>
<name>local-snapshots</name>
<url>${snapshot.repository.url}</url>
</snapshotRepository>
</distributionManagement>
Also refer to this to work around the "plugin execution not covered by lifecycle" error in Eclipse/SpringToolSuite
see: How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
I've found a solution that worked fine for me. Just added the gmaven-plugin like in the pom-snippet below and the versions will be adapted to the last git-tag.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>project.artifact.version='${git.closest.tag.name}';</source>
</configuration>
</execution>
</executions>
I've also used groovy-maven-plugin to update project.properties. Without this pom.xml was generated with variables that have not been parsed.
project properties
<properties>
<gitClosestTagName>${git.closest.tag.name}</gitClosestTagName>
<gitClosestTagCommitCount>${git.closest.tag.commit.count}</gitClosestTagCommitCount>
</properties>
build final name atteribute
<finalName>${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}</finalName>
plugin definition
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>update-finalname</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.build.finalName="${project.artifactId}-${gitClosestTagName}.${gitClosestTagCommitCount}";
project.properties['gitClosestTagName']=${git.closest.tag.name};
project.properties['gitClosestTagCommitCount']=${git.closest.tag.commit.count};
println("project.build.finalName=${project.build.finalName}");
</source>
</configuration>
</execution>
</executions>

Maven can't compile project even when I can debug it

I transferred a big java project to maven and replaced all the libraries used with maven and I can run debug or start just fine meaning that it works normally but for some reason whenever I try to run maven test or install or anything that tries to compile it using maven it fails.
This is my pom file (I use nexus for third party jars):
<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>pbclient2</groupId>
<artifactId>pbclient2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Name</name>
<description>Description</description>
<dependencies>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
.
.
.
<dependency>
<groupId>mxmlc</groupId>
<artifactId>mxmlc</artifactId>
<version>1.0</version>
<classifier>mxmlc</classifier>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin> <groupId>com.google.appengine</groupId> <artifactId>appengine-maven-plugin</artifactId>
<version>1.9.32</version> <configuration> <enableJarClasses>false</enableJarClasses>
</configuration> <executions> <execution> <goals> <goal>endpoints_get_discovery_doc</goal>
</goals> </execution> </executions> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<phase>test</phase>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build></project>
I have tried a lot of plugins and tried deleting the .m2 repository but nothing seems to help.
All the errors I get are
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[10,24] package com.pb.hibernate does not exist
or
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[192,36] cannot find symbol
symbol: class PbPwoNamingConfiguration
location: class pb.ui.panels.admin.workorders.configuration.namingConvention.GenericNamingConventionTableModel
The package does exist and I don't understand why this won't work like its supposed to.
Am I doing something wrong since I just started using maven.
The error messages suggest to me that either the package com.pb.hibernate doesn't exist in your project (maybe it has been renamed and your IDE didn't update every use properly) or it exists in an external dependency which your IDE has somehow got in its path when running/debugging, but the dependency isn't defined correctly in your pom, and so running mvn clean install fails

How to perform build and execute sh in sequence using maven

I am using this section of pom.xml to execute a sh file which will trigger my regression test.
This section invokes the sh file.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>Regression_Test</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${basedir}/../../qascripting/Vdopia_Automation/exe/hudson_tc_execute.sh</executable>
</configuration>
</plugin>
When I execute command mvn clean package -- it just builds the code, doesn't trigger the sh and when I use command mvn clean verify --- it executes the sh but doesn't build the code. Now I want a command which should build the code first and then execute the sh.
whole pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vdopia</groupId>
<artifactId>hudson</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<url>http://maven.apache.org</url>
<properties>
<gson.version>2.2.4</gson.version>
<guava.version>18.0</guava.version>
<junit.version>4.10</junit.version>
<netty.version>4.0.25.Final</netty.version>
<wurfl.version>1.5.1</wurfl.version>
<slf4j.version>1.7.7</slf4j.version>
<redis.version>2.4.2</redis.version>
<logger.version>0.3.1</logger.version>
<org.apache.commons.pool.version>1.6</org.apache.commons.pool.version>
<execplugin.version>1.3.2</execplugin.version>
<commons.codec.version>1.9</commons.codec.version>
<geoip.version>1.2.14</geoip.version>
<org.json.version>20140107</org.json.version>
<jacoco.version>0.7.2.201409121644</jacoco.version>
<spymemcached.version>2.11.5</spymemcached.version>
<aspectjweaver.version>1.8.0</aspectjweaver.version>
<aspectjrt.version>1.8.0</aspectjrt.version>
<apacheasynchttpclient.version>4.1</apacheasynchttpclient.version>
<shadedjar.version>2.3</shadedjar.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version> <executions> <execution> <goals> <goal>prepare-agent</goal>
</goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase>
<goals> <goal>report</goal> </goals> </execution> </executions> </plugin -->
<!-- To download and link source code in eclipse -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execplugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${shadedjar.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.vdopia.rtb.netty.Server.HudsonMain</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- REGRESSION TEST -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>Regression_Test</id>
<phase>verify</phase>
<!-- <phase>generate-test-sources</phase> -->
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${basedir}/../../qascripting/Vdopia_Automation/exe/hudson_tc_execute.sh</executable>
</configuration>
</plugin>
<!-- END -->
</plugins>
</build>
<profiles>
<profile>
<id>code-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<modules>
<module>utils</module>
<module>rtb</module>
<module>adResponse</module>
<module>DAL</module>
<module>cache</module>
<module>redis</module>
<module>extRequestProcessor</module>
<module>netty</module>
<module>ResponseGenerator</module>
<module>RequestHandler</module>
<module>Filter</module>
<module>fluentData</module>
<module>vast</module>
<module>externalcache</module>
<module>templates</module>
<module>statistics</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
The maven lifecycle controls the order. So you're doing fine by putting your sh command into the verify phase. Remember that if you get a failure in an earlier phase, then maven stops rather than moving forward to the next phase. Here's the order the phases execute in:
https://maven.apache.org/ref/3.3.3/maven-core/lifecycles.html
I put together a minimal pom and it works.
Here's my pom
<modelVersion>4.0.0</modelVersion>
<groupId>com.simuquest.qp</groupId>
<artifactId>example1</artifactId>
<version>1.0.13333</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>Regression_Test</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<workingDirectory>${basedir}\target</workingDirectory>
<arguments>
<argument>-cp</argument>
<argument>${basedir}\target\example1-1.0.13333.jar</argument>
<argument>example1.NewMain</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
and here's the output when I do "mvn install"
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
--- maven-jar-plugin:2.3.2:jar (default-jar) # example1 ---
Building jar: C:\Users\Administrator\Documents\NetBeansProjects\example1\target\example1-1.0.13333.jar
--- exec-maven-plugin:1.2.1:exec (Regression_Test) # example1 ---
hello
--- maven-install-plugin:2.3.1:install (default-install) # example1 ---
Installing C:\Users\Administrator\Documents\NetBeansProjects\example1\target\example1-1.0.13333.jar to C:\Users\Administrator\.m2\repository\com\simuquest\qp\example1\1.0.13333\example1-1.0.13333.jar
Installing C:\Users\Administrator\Documents\NetBeansProjects\example1\pom.xml to C:\Users\Administrator\.m2\repository\com\simuquest\qp\example1\1.0.13333\example1-1.0.13333.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
So you can now compare working and not-working pom files. You can do a binary search to find out what parts of your pom are causing you grief. Why don't you start by dropping just about all those plugins. Remember that you only need to build without error in order to get through the phases and reach the verify phase.

Categories

Resources