I have the following plain pom running by Maven 3.0.4.
<?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.example</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</project>
I am trying to override default settings in command line like this:
mvn -Dproject.build.finalName=build clean package
But this this is ignored, and I get test-1.0.jar. I've tried to change another properties, like outputDirectory, directory, artifactId, but also failed.
What is the proper way to do this thing?
See Introduction to the POM
finalName is created as:
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
One of the solutions is to add own property:
<properties>
<finalName>${project.artifactId}-${project.version}</finalName>
</properties>
<build>
<finalName>${finalName}</finalName>
</build>
And now try:
mvn -DfinalName=build clean package
Related
I have encountered a strange bug while trying to deploy new release builds to my company's JFrog.io (fka: ArtifactoryOnline.com) repository. The project I'm working on has multiple maven modules, all under a single parent. When I upload the JAR files that maven builds to JFrog, the generated POM file is being populated with the incorrect parent artifactId.
I spent a great deal of time and could not find any problems with my company's codebase for the project, so I decided if I could reproduce the error from scratch. Thus I made this throwaway project to demonstrate the bug. For those uninterested in downloading the full project, here are the relevant POM files:
The parent POM, "blueberry":
<?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.nbyrd</groupId>
<artifactId>blueberry</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>blueberryjam</module>
<module>berries</module>
</modules>
</project>
Dependant POM 1: "berries":
<?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">
<parent>
<artifactId>blueberry</artifactId>
<groupId>org.nbyrd</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>berries</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Dependant POM 2, "berry-jam":
<?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">
<parent>
<artifactId>blueberry</artifactId>
<groupId>org.nbyrd</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blueberry-jam</artifactId>
<dependencies>
<dependency>
<groupId>org.nbyrd</groupId>
<artifactId>berries</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
(For what it's worth, all of these POM files were generated in their entirety by JetBrains IntelliJ.)
Pretty straight forward at this point: I have two Maven modules--"berries" and "berry-jam"--that are housed under a central parent module, "blueberry". berry-jam uses berries as a dependency, although I'm not sure if that's relevant to the problem.
When I build the project, I get two JAR files: berries-1.0.jar and berry-jam-1.0.jar. This is as expected. At this point, I would upload these artifacts to Artifactory so that other projects may reference them. And this is where the trouble starts.
When I upload berries-1.0.jar, Artifactory generates the following POM 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">
<parent>
<artifactId>berries</artifactId>
<groupId>org.nbyrd</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>berries</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
As you can see, the generated POM defines the parent artifactId as "berries", which is wrong.
The same problem occurs when I upload berry-jam-1.0.jar:
<?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">
<parent>
<artifactId>blueberry-jam</artifactId>
<groupId>org.nbyrd</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blueberry-jam</artifactId>
<dependencies>
<dependency>
<groupId>org.nbyrd</groupId>
<artifactId>berries</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
In both cases, I would expect the parentId to be "blueberry", as it is explicitly stated in both of the child-modules' POM files. These incorrect artifactIds make it impossible to use these libraries. If a third-party application attempts to use these libraries, maven will produce the following warning when downloading dependencies and the build will fail:
[WARNING] The POM for org.nbyrd:berries:jar:1.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
This functionality used to work correctly in the past when uploading to Artifactory, so I'm not sure if something has changed in how the tool works or if I have simply done something wrong. Any thoughts?
When you use mvn deploy maven deploys the pom.xmlfile as separated artifact. But when you uploads the jar file with artifactory's web ui and asks artifactory to generate the pom file, I guess it generates it from the data presents in the jar. So the artifactory isn't aware about existing of a parent project.
I had similar problem and my guess was that artifactory is trying to fix pom by changing first artifactId value it can find. Not seeing that it's inside parent node.
So I moved parent node below artifactId/version and that worked for me.
<?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>
<artifactId>berries</artifactId>
<version>2.0</version>
<parent>
<artifactId>berries</artifactId>
<groupId>org.nbyrd</groupId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I have a maven project that contains two submodules, one depends on there other.
The project has no code but maven is ok with that. If I perform mvn package it passes ok and generates (empty) jar files.
However if I do mvn dependency:list I get the following error:
Failed to execute goal on project foob-two: Could not resolve dependencies for project com.example.foob:foob-two:jar:1.0.0-SNAPSHOT: Failure to find com.example.foob:foob-one:jar:1.0.0-SNAPSHOT in [Repo]
It seems like the maven dependency plugin only works after the modules have been uploaded to the local repo.
Strangely if I do the dependency list at the same time as package, ie mvn package dependency:list, it works. So it seems that maven has a different dependency resolution mechanism in some contexts.
Can anyone explain the behaviour? Can I run mvn dependency:list as a standalone command?
Here's the root 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.example.foob</groupId>
<artifactId>foob</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>foob-one</module>
<module>foob-two</module>
</modules>
</project>
Here's the first subproject:
<?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">
<parent>
<groupId>com.example.foob</groupId>
<artifactId>foob</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foob-one</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
Here's the second project:
<?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">
<parent>
<groupId>com.example.foob</groupId>
<artifactId>foob</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>foob-two</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.example.foob</groupId>
<artifactId>foob-one</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
mvn dependency:list can be run on its own. It appears as if your project is failing because of missing dependencies. Try mvn install first.
how to make one module depends on another module artifact in maven multi-modules
I am doing a Maven project with Intellj Idea in which I am trying to use neo4j.
I have an error of "unable resolve symbol neo4j" on (import org.neo4j.driver.v1.*;).
I have brought in the neo4j jar files to the project and believe I have a correctly set up pom file. I will post both though with this question below.
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.example</groupId>
<artifactId>NeoImport</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>NeoImport</name>
<description>Import</description>
<dependencies>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
</build>
</project>
Project Setup:
Thanks!
I have the following Maven organization:
- ./pom.xml (top-level project, which defines the 4 modules below)
- ./a/pom.xml (library jar)
- ./b/pom.xml (library jar)
- ./c/pom.xml (war)
- ./d/pom.xml (executable jar)
For building and deploying the c project, I do:
mvn verify tomcat7:redeploy -pl c -am
For building and executing the d project, I do:
mvn verify exec:java -pl d -am
For d there is a problem. Maven reports:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli)
on project parent: The parameters 'mainClass' for goal
org.codehaus.mojo:exec-maven-plugin:1.4.0:java are missing or invalid -> [Help 1]
This is indeed correct, the parent pom.xml has no configuration for exec. Only the d project has a configuration for exec.
This question is a little variation of question maven - advice on usage of multi-modules (jar, war, ...) project, so I decided to dedicate a separate question for it.
Why does Maven try to exec on the parent project?
update
I abstracted the same problem in following three pom files:
The parent pom:
<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>test</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent</name>
<modules>
<module>a</module>
<module>b</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The a pom:
<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>
<parent>
<groupId>test</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>a</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>a</name>
</project>
The b pom:
<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>
<parent>
<groupId>test</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>b</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>b</name>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>MyMainClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
The command I am executing is:
mvn verify exec:java -pl b -am
This can also be found at https://github.com/jeperjaperjieper/issue-33197130.
I can't cure your problem, but I can give you a recipe. You may have hit a maven issue.
You don't have to use -pl and build from the top every time.
I would expect it to work if you just run 'mvn' (no -pl) at the top; it probably doesn't take very long to build the first pieces.
If you don't want to do that, then you need to run 'mvn install' for the pieces that come first, and then you'll be able to cd into the last piece and build it.
I recommend opening up a JIRA issue for Maven on this; it seems as if you've exposed a problem with -pl, but the best way to find out is to post an issue with a test case and poke the Maven user mailing list.
Try mvn exec:java -Dexec.mainClass="com.example.Main" to run your d project.
Hi I'm working on project which created in netbeans 8.0.1.
It is created in Maven.Now after completion when try to open created jar its not getting executed.
below is the pom.xml file.
Please advise.
<?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.elitechweb.asm</groupId>
<artifactId>Test</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>
<build>
</build>
</project>
Added maven-install-plugin-2.3.1 jar file. and changes in POM.xml respective jar