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.
Related
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.
IntelliJ displays these warning messages at Modules
enter image description here " Module xx is imported From Maven. Any changes made in its configuration might be lost after reimporting." (Note, this happens only when I press the Apply button on the Module)
I want to know what this means in detail and the solution...
For information Here:
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>me.codingtime</groupId>
<artifactId>NetworkPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>NetworkPlugin</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
This error means that you must not modify the project structure and build configuration like project dependencies, compiler settings, sources/resources directories etc using IDE UI dialogs. Instead, you must do corresponding changes in the Maven pom.xml file.
Because otherwise you will loose all such changes made in IDE UI after the project fill be Reloaded by the IDE from the maven build files (pom.xml).
I am using Jitpack to get one of my github repositories as a dependency, and then using maven shade to include said dependency in the compiled output of the project. However, only 2 of the 3 classes in the dependency are being shaded into the final jar. There seem to be no compilation issues (syntax or maven), yet at runtime the missing class causes a NoClassDefFoundError to be thrown. Decompiling the jar shows that ConfigManager and Utils are shaded, but Logger is ignored.
Dependency: https://github.com/Benlewis9000/PluginToolsAPI
Project 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>com.github.benlewis9000</groupId>
<artifactId>PluginToolsAPITestPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- Access github repositories -->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Benlewis9000</groupId>
<artifactId>PluginToolsAPI</artifactId>
<version>82aaa66bbf</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Please let me know if any info is lacking,
Thank you
I didn't know about Jitpack, it does look rather useful!
I've used this config in the past for shade:
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
</filter>
</filters>
</configuration>
Any code referenced below is from the project here
For the AWS Lambda, I have been trying to create a jar file based on the maven configuration defined here.
<?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>be.quodlibet</groupId>
<artifactId>HelloLambda</artifactId>
<version>1.0-SNAPSHOT</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>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
When I try and build the fat JAR, upload it to AWS Lambda console, I see the error
The following package be.quodlibet.hellolambda was not added to the jar resulting in a
"errorMessage": "Class not found: be.quodlibet.hellolambda.helloHandler",
"errorType": "java.lang.ClassNotFoundException"
As #khmarbaise said in the comments, make sure you run "mvn clean package" and not "mvn clean assembly:single".
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.