I came across a problem with a maven project build.
My project structure is as follows
my-message
|
---my-message-api
|
--- my-message-provider
Below is the pom.xml code
my-message.pom
<parent>
<groupId>com.xiaofeng.my</groupId>
<artifactId>my-parent</artifactId>
<version>0.0.1</version>
</parent>
<artifactId>my-message</artifactId>
<version>${my-message.version}</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<properties>
<my-message.version>0.0.1-SNAPSHOT</my-message.version>
</properties>
<modules>
<module>my-message-api</module>
<module>my-message-provider</module>
</modules>
my-message-api.pom
<parent>
<groupId>com.msh.my</groupId>
<artifactId>my-message</artifactId>
<version>${my-message.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
my-message-provider.pom
<parent>
<groupId>com.msh.my</groupId>
<artifactId>my-message</artifactId>
<version>${my-message.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>my-message-provider</artifactId>
<dependencies>
<dependency>
<groupId>com.msh.my</groupId>
<artifactId>my-message-api</artifactId>
<version>${my-message.version}</version>
</dependency>
</dependencies>
maven install output
Failed to execute goal on project my-message-provider: Could not resolve dependencies for project
com.msh.my:my-message-provider:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.msh.my:my-message-api:jar:0.0.1-SNAPSHOT:
Failed to read artifact descriptor for com.msh.my:my-message-api:jar:0.0.1-SNAPSHOT: Could not find artifact com.msh.my:my-message:pom:${my-message.version}
in nexus (http://nexus_url:8081/nexus/content/groups/public)
Why can't maven parse the expression in the parent's version? please help me
Because you can't use a variable in the specification of a parent in a module. Maven needs to be able to resolve the whole model structure before it can resolve variables.
Related
My goal is to turn an existing maven project (char-counter) into a module of my multi-module maven project. How can I do this? I use Eclipse 4.16.0.
Here is the structure of my projects.
You can include the sub-modules inside your parent maven project in following way.
Inside your multi-module-project pom.xml
<modules>
<module>char-counter</module>
</modules>
See here: Maven Multiple module
Assuming that you want to convert your char-counter project to multi-module-project.
You need to have following in your multi-module-project pom.
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Anagram<module>
<module>Calculator<module>
</modules
And then in Anagram project's pom :
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Anagram</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
And in Calculator project's pom:
<parent>
<groupId>com.parent</groupId>
<artifactId>multi-module-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.child</groupId>
<artifactId>Calcultor</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
Also you need to add dependency of one module to other,in which you want to use the code from other module and then you need to deploy the artifact(module) which has dependency included in it and has starting point to run (like main).
Well I'm working on a company POM Maven structure. I want a structure like the example below. Now I have two questions!
Is this possible for a project to call the parent pom? (considering
that they are all installed in the local Maven repository).
If I adda License block to the Company POM, do I have to add to the
project POM a new License block?
All feedback, suggestions etc are welcome. Thank you in advance!
Company
Company POM
Contains organization information, not to much.
<groupId>org.company</groupId>
<artifactId>company</artifactId>
<version>1</version>
<modules>
<module>company-parent</module>
</modules>
Company Parent POM
Defines for all the projects basic dependencies/plugins (management).
<parent>
<groupId>org.company</groupId>
<artifactId>company</artifactId>
<version>1</version>
</parent>
<artifactId>company-parent</artifactId>
Project
Project POM
Project based organization information (developers etc).
<parent>
<groupId>org.company</groupId>
<artifactId>company-parent</artifactId>
<version>1</version>
</parent>
<groupId>org.company.project</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<modules>
<module>project-parent</module>
</modules>
Project Parent POM
Defines for the current project used dependencies/plugins (management).
<parent>
<groupId>org.company.project</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
</parent>
<artifactId>project-parent</artifactId>
<modules>
<module>company-module-1</module>
<module>company-module-2</module>
<module>company-module-3</module>
</modules>
Project Module POM's
The modules with each his own buid, dependencies and stuff.
Module 1
<parent>
<groupId>org.company.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>project-module-1</artifactId>
Module 2
<parent>
<groupId>org.company.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>project-module-2</artifactId>
Module 3
<parent>
<groupId>org.company.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>project-module-3</artifactId>
A Maven child project does not "call" a parent project. The POM is declarative, not imperative. Similar to Java class inheritance the child gets the parent's settings and can override them or add new ones. See Maven, POM Reference, 2.2.2. Inheritance.
So, no, you don't have to declare the parent project's licence settings in the child project once again if they are supposed to be the same there.
I have a maven project with a parent pom and child modules, structured like this:
root/pom.xml
root/parent/pom.xml
root/child1/pom.xml
root/child2/pom.xml
root/child2/child21/pom.xml
Every child pom and the root pom declare root/parent as their parent. child21 has child1 as a dependency.
When I try to execute mvn install from the child1 directory, maven successfully builds and installs the child1 jar. But when i execute mvn install from either the child2 or child21 directories, maven errors out with the following:
[ERROR] Failed to execute goal on project child21: Could not resolve dependencies for project groupId:child21:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at groupId:child1:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for groupId:child1:jar:0.0.1-SNAPSHOT: Could not find artifact groupId:parent:pom:0.0.1-SNAPSHOT in jme-repo (http://updates.jmonkeyengine.org/maven/) -> [Help 1]
I have tried googling for what might be wrong with my project structure with no luck. Can anyone help suggest ways to get child21 to build?
My poms contain:
Root
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
Parent
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<dependencyManagement>
<repositories>
<repository>
<id>jme-repo</id>
<name>JME3 Official Maven Repo</name>
<url>http://updates.jmonkeyengine.org/maven/</url>
</repository>
</repositories>
<build>
<plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugins>
</build>
Child 1
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<dependencies>...</dependencies>
Child 2
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>child2</artifactId>
<packaging>pom</packaging>
<modules>
<module>child21</module>
</modules>
Child 21
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<artifactId>child21</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>child1</artifactId>
</dependency>
</dependencies>
UPDATE WITH SOLUTION
Based on the accepted answer below, I added the parent project as a module of the root pom:
<parent>
<groupId>groupId</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>./parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
<packaging>pom</packaging>
<modules>
<module>parent</module>
<module>child1</module>
<module>child2</module>
</modules>
Then when developers build the project for the first time, the parent pom is installed. Subsequently they will be able to build the child2 and child21 projects independently.
This is a pretty awkward module structure, but it can still work. The problem is that when you are building module child21 (or child2), the child1 dependency is not a part of the current build, but is looked up in the repository. So is the parent of that dependency, which is the parent module. However, I assume, parent was never installed there - if you run mvn clean install on root, it does not build the parent, which is only referenced in the child modules by relative paths.
To fix it you must first install the parent POM into the repository. Run mvn install in the parent module. After that, build child1 - it will be installed into the repository as well. Now everything what is needed for building module child21 is available in the repository.
Change child21 to inherit from its parent - child2, see below:
<parent>
<groupId>groupId</groupId>
<artifactId>child2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
I have made my application multi-module with the plan of eventually splitting them into multiple repos.
I'm having problems figuring out how to make mvn spring-boot:run work with my layout (which may be the problem).
actually directory structure is
xenoterracide/
rpf/
rpf-application/
when I run mvn test from xenoterracide that passes fine, and when I start my Application class that works fine.
if I cd into rpf-application and run mvn compile it tells me that it can't find the dependencies, I'm guessing this is because things are meant to be run from the repository root.
[INFO] ------------------------------------------------------------------------
[INFO] Building rpf-application 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.xenoterracide:security-rbac-jpa:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:http:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:rpf-domain:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:rpf-liquibase:jar:0.1.0-SNAPSHOT is missing, no dependency information available
if I try to set the start-class in the xenoterracide/pom.xml it tells me it can't find the class (because of course it's in rpf-application).
rpf-application/pom.xml
<parent>
<artifactId>rpf</artifactId>
<groupId>com.xenoterracide</groupId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../rpf/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rpf-application</artifactId>
<properties>
<start-class>com.xenoterracide.RpfApplication</start-class>
</properties>
<dependencies>
<!-- internal -->
<dependency>
<groupId>com.xenoterracide</groupId>
<artifactId>security-rbac-jpa</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xenoterracide</groupId>
<artifactId>http</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xenoterracide</groupId>
<artifactId>rpf-domain</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xenoterracide</groupId>
<artifactId>rpf-liquibase</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
...
rpf/pom.xml
<parent>
<artifactId>xenoterracide</artifactId>
<groupId>com.xenoterracide</groupId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rpf</artifactId>
<packaging>pom</packaging>
<modules>
<module>../rpf-domain</module>
<module>../rpf-application</module>
<module>../rpf-liquibase</module>
</modules>
pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.xenoterracide</groupId>
<artifactId>xenoterracide</artifactId>
<packaging>pom</packaging>
<version>0.1.0-SNAPSHOT</version>
<modules>
<module>util</module>
<module>http</module>
<module>security-rbac-api</module>
<module>security-rbac-jpa</module>
<module>hibernate</module>
<module>entity-jpa</module>
<module>rpf</module>
<module>test-repositories</module>
<module>entity-api</module>
</modules>
<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>1.1.2.RELEASE</version>
</parent>
how can I make mvn spring-boot:run work from either the root of the repository (xenoterracide) or from rpf-application?
I also have a multi-project Spring Boot app and you can't do it from the parent since there could be multiple modules and it would not know which to run. You can do it from the child module if you first install the rest of the project to local Maven repository. So from your xenoterracide run:
mvn install
Assuming that works it will put your SNAPSHOT versions into your local repository. You can then change to your rpf-application and then run:
mvn spring-boot:run
I've never really used this as a way to run it so maybe you can explain what your need is and we can see if there is another way that may be better. I did do it with my project and it works but you have to be conscious of where the working directory is for your environment specific configuration files.
I've been previously managing a 3-module project as 3 seperate maven projects. As this project has been moving forward, I decided I ought to take advantage of the dependency management of maven2 to streamline integration between these 3 evolving modules.
I defined a super-project that deploys as POM. Some shared dependencies are defined here, and the modules are defined in the POM in the order of dependency from the least dependent module to the most dependent module. Each module has a POM definition back to the parent, and where it applies there are dependencies from one module to the deployed artifact of another module. I'll include possibly worthwhile pom.xml lines at the end.
On to the problem, I setup this project yesterday and was able to get each module building and working on its own. I then come back today to work on one of the modules now that some fresh requirements have come in and all of sudden everything is breaking. I'm editing the projects in Eclipse, and each time I modify a file, it no longer can resolve any of the classes defined within the same project. That is to say if I have a class foo.bar.class1 and it has an object of foo.bar.class2, Eclipse (and the compiler at large) complains that it cannot resolve class foo.bar.class2... Now this is blowing my mind because this other class is in the same project and package. Similar issues are also present for classes not in the same package.
Is there something broken in my maven setup, or does anyone have any idea why these projects can't even resolve classes in the same package??
-::POMs::-
Parent -> /path/to/project/mainApp
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>mainApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main App</name>
<modules>
<module>Broker</module>
<module>Soap</module>
<module>UI</module>
</modules>
Broker -> /path/to/project/mainApp/Broker
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
Soap -> /path/to/project/mainApp/Soap
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>SOAP</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
...
UI -> /path/to/project/mainApp/UI
<parent>
<artifactId>mainApp</artifactId>
<groupId>com.moremagic</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>UI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>SOAP</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.moremagic</groupId>
<artifactId>Broker</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
...
It sounds like the problem is with your Eclipse setup and not Maven.
Does mvn compile work from the command-line within your projects? From both the parent project and each individual module (after doing mvn install for the dependencies)?
Are you using a Maven plugin for Eclipse, such as m2eclipse? Check that it is configured to load dependent projects from within Eclipse, rather than looking to the repository ("Enable Workspace Resolution"). What happens if you do Project > Clean to clean out all of the projects?