Maven + Vert.x - "package junit.framework does not exist' - java

I have the following pom.xml file:
<?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>cdt</groupId>
<artifactId>cdt-hive-vertx</artifactId>
<version>3.4.2</version>
<packaging>jar</packaging>
<name>cdt-hive-vertx</name>
<url>http://maven.apache.org</url>
<properties>
<exec.mainClass>cdt.HelloWorldEmbedded</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<!--
You only need the part below if you want to build your application into a fat executable jar.
This is a jar that contains all the dependencies required to run it, so you can just run it with
java -jar
-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${exec.mainClass}</Main-Class>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
</transformer>
</transformers>
<artifactSet>
</artifactSet>
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<!-- run the application using the fat jar -->
<id>run-app</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>target/${project.artifactId}-${project.version}-fat.jar</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>staging</id>
<repositories>
<repository>
<id>staging</id>
<url>https://oss.sonatype.org/content/repositories/iovertx-3684/</url>
</repository>
</repositories>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
when I run:
mvn clean package exec:java
I get:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project cdt-hive-vertx: Compilation failure: Compilation failure:
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[3,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[4,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[5,23] package junit.framework does not exist
[ERROR] /Users/alexamil/WebstormProjects/nabisco/cdt-hive-vertx/src/test/java/cdt/HelloWorldEmbeddedTest.java:[7,45] cannot find symbol
the error is happening because of the single test case I have:
package cdt;
import junit.framework.Test; // cannot find these files
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class HelloWorldEmbeddedTest extends TestCase {
}
but I have junit referenced in my pom.xml file in the <dependencyManagement> section.
Anyone know what could be wrong?

Few things over the implementation :-
First, since the module uses the packages from junit, you should include that as well into <dependencies> tag instead of <dependencyManagement> as :
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope> <!-- this could be just for tests -->
</dependency>
</dependencies>
Second, Please note though I cannot find the java docs for the specified version of junit artifact but trusting this question seems to me that 4.+ version of the library uses a class #org.junit.Test instead of what you had used in your class i.e. #junit.framework.Test. You might want to change to the latest package name if the version has so in your classes.

Related

Java Maven project won't get deployed to Heroku

I'm trying to deploy a simple app using Heroku but I keep on getting the same error which is:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
I thought there is a problem with my pom.xml file buta after changing it multiple times, it still didn't work and I can't seem to figure out why.
Here is my pom.xml file:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>UserManagement</groupId>
<artifactId>UserManagement</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Repo-X</name>
<description>Software repository</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>8.0.30.2</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
To solve the error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project
I'd suggest several options:
try to add explicitly properties inside your POM before dependencies like:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
*based on your Java project version.
try to configure by specifying a <configuration> element in format:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
try to upgrade/downgrade version of maven-compiler-plugin
then redeploy again.
If nothing helps, improve your question with updated investigations, please.
Also it'd be more informative if you update the question with your specific attempts, what exactly you tried to do to solve it.

Java giving NoClassDefFoundError when importing maven package

I have a simple java code, App.java. I am trying to import the apache commons Fraction class from the apache commons math3 library. So, as a sample code, I put this in my App.java:
package myApp;
import org.apache.commons.math3.fraction.Fraction;
public class App
{
public static void main( String[] args )
{
Fraction f = new Fraction(2, 3);
System.out.println( "Hello World!" );
System.out.println( f );
}
}
Using the following POM:
<?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>myApp</groupId>
<artifactId>Proj1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Proj1</name>
<url>http://www.example.com</url>
<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>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I have tried to put the plugin suggested by utdemir in his answer to a similar question, but in my case, when I run:
mvn package
java -cp target/Proj1-1.0-SNAPSHOT.jar myApp.App
While it apparently compiles properly, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/fraction/Fraction
at myApp.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.fraction.Fraction
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 1 more
What should I do?
Its much easier to run your app using mvn, rathen than by calling java directly. This is because in the later case you need to manually set the classpath to the correct value using the -cp flag. This can lead to errors, like in your case.
Here's how you can run your app using mvn
mvn exec:java -Dexec.mainClass="myApp.App"
More details can be found here

How to create a runnable jar file with AspectJ?

I'm using Eclipse to compile java code with aspectj.
My code (with the aspect) works fine, but I'm struglling to create a jar file of this my code.
For example, if I select Export > Runnable JAR file, in the combo box I don't see my project (all the other project that not based on aspecj are showing up in the combo box).
If you like to have repeatable builds which work from command line as well as from IDEs like Eclipse or IntelliJ IDEA, I recommend a Maven build. The onejar-maven-plugin creates a runnable JAR including AspectJ runtime and all other declared dependencies for you:
<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>de.scrum_master.stackoverflow</groupId>
<artifactId>my_project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.source-target.version>1.7</java.source-target.version>
<aspectj.version>1.8.8</aspectj.version>
<main-class>de.scrum_master.app.Application</main-class>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<!--<showWeaveInfo>true</showWeaveInfo>-->
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java.source-target.version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<!--<verbose>true</verbose>-->
<!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>-->
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<mainClass>${main-class}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<onejarVersion>0.96</onejarVersion>
<mainClass>${main-class}</mainClass>
<attachToBuild>true</attachToBuild>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>OneJAR googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
</dependencies>
<organization>
<name>Scrum-Master.de - Agile Project Management</name>
<url>http://scrum-master.de</url>
</organization>
</project>
Try to create a normal run configuration with the same start class as your AspectJ run configuration. When you create your runnable JAR, select the normal run configuration. The resulting JAR will have AspectJ support.
You can find here the answer :
https://www.eclipse.org/forums/index.php/t/204968/
The runnable jar exporter only works with Java Application type launch configs, but that shouldn't be a problem. Create a normal Java Application launch config with your main class and export the runnable jar based on that newly created launch config. It should work.

Maven running tests annotated with junit #Ignore when building Java project

I've annotated a bad test with #Ignore, both on the method-level and on the class level. When running the test through the command line (I've tried "mvn clean install", "mvn test", "mvn clean install -DskipTests; mvn test"), however, the #Ignore annotation is ignored, the test is run, and- as it is a bad test- it fails.
Here is the test:
public class UserTest extends PersistentTestBase {
#Test
#Ignore
public void testPersistence() {
...
}
}
And here is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
...
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-legacy</artifactId>
<version>2.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
...
<!-- For dep management, see Mykong.com's "How to create a jar file with Maven" -->
<build>
<plugins>
<!-- Necessary to force language level of Java 8 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<junitArtifactName>junit:junit-dep</junitArtifactName>
<useFile>false</useFile>
<trimStackTrace>false</trimStackTrace>
<reuseForks>false</reuseForks>
<forkCount>1</forkCount>
</configuration>
</plugin>
<!-- Packages into a jar, looking for deps in target/dependency-jars -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>...Application</mainClass>
<classpathPrefix>dependency-jars</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Moves all compiled deps to target/dependency-jars -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>...Application</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Worth noting that the test is skipping when the class is run in Intellij IDEA 14, and that there are some other issues with tests failing on mvn test that are passing in Intellij (but are out of the scope of this question). Thank you for the help!
For those who are working with Junit 5.
#Ignore did not work formaven surefire neither Intellij tests even if I had already included junit-vintage-engine
I used #Disabled and it worked for maven at least!
Wemu posted the solution:
I think you can simply remove:
junit:junit-dep from the
surefire config – wemu Nov 20 at 7:10
Removed the element and all tests passed!
I had a same problem with the JUNIT library. After so many tries, it worked with the Pom.xml below:
<repositories>
<repository>
<id>junit</id>
<url>http://junit.org</url>
</repository>
</repositories>
<dependencies>
<dependency><groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version></dependency>
</dependencies>
For me the solution was to simply update the JUnit version to 4.13:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>

flattened pom is not being used?

It is a multi-module maven project. I have included flatten-maven-plugin in my parent pom
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
</configuration>
defined a property scl_version in parent pom and used ${scl_version} in of child pom. Value is 0.0.1 .
when i run mvn flatten:flatten
It generates a warning :
[WARNING] 'version' contains an expression but should be a constant.
A flattened pom is created in all modules including parent and all the childs.
Flattened pom has value of the property in version tag of child pom. But when i give, mvn install it still gives warning that version should be constant but it is an expression.
http://mojo.codehaus.org/flatten-maven-plugin/plugin-info.html
But documentation says:
This MOJO realizes the goal flatten that generates the flattened POM
and potentially updates the POM file so that the current
MavenProject's file points to the flattened POM instead of the
original pom.xml file. The flattened POM is a reduced version of the
original POM with the focus to contain only the important information
for consuming it. Therefore information that is only required for
maintenance by developers and to build the project artifact(s) are
stripped.
so when i do mvn install it should not generate warning.
mvn install and mvn flatten:flatten both generates this warning:
[WARNING] 'version' contains an expression but should be a constant.
Am i missing something, is it not using flattened-pom.xml.
Do i need to specify something.
PARENT POM:
<?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>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<modules>
<module>Resources</module>
<module>ResourceTree</module>
<module>Service</module>
<module>Transport</module>
<module>Branding</module>
properties tag starts here
<scl_version>0.0.1</scl_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<karaf.deploy.build.folder>${env.KARAF_BASE}/deploy</karaf.deploy.build.folder>
property tag ends here
<profiles>
<profile>
<id>code_coverage</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.0.201403182114</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0-beta-2</version>
<configuration>
<flattenMode>ossrh</flattenMode>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>0.7.0.201403182114</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
generated flattened pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
</project>
property is used in grand grand child pom ( for trail, if successfull without warning, i can iuse it everywhere):
<groupId>org.a.b</groupId>
<artifactId>CD<artifactId>
<version>${scl_version}</version>
<packaging>bundle</packaging>
<name>CD</name>
<description>OSGi bundle project.</description>
Apart from this, it has bundle plugin dependency plugin and some dependencies. In flattened pom ofthis child this version is resolved to 0.0.1
I mailed to developer of this plugin and his response is:
The warning is coming from Maven, based on the original pom.xml
Before Maven starts executing, a buildplan is created and the pom.xml
is analyzed, causing this warning. The flatten-maven plugin kicks in
later in the process generating the flattened pom.xml and making sure
that's the file being installed/deployed. Your issue can't be fixed by
the flatten-maven-plugin and won't be fixed in Maven Core (the warning
is there for a good reason).
So, it answers the question very well.

Categories

Resources