I use IDEA,My springboot app contains multiple modules like that:
parent
-web
-service
-dao
There is a jar dependency common:1.2.0-SNAPSHOT in service module defined in pom.xml, I updated its version to 1.3.0-SNAPSHOT, after that i do maven reimport and run mvn clean install -U but these two versions still in dependencies list, and in dependency tree, two jar in the dependencies, also when i run the app, it throw NoClassDefFoundError error which i added in 1.3.0-SNAPSHOT
This is my maven dependenct tree:
service:jar
+- dao:jar
\- common:jar:1.3.0-SNAPSHOT
web:jar
+- service:jar
+- dao:jar
\- common:jar:1.2.0-SNAPSHOT
\- others:jar
service pom dependency:
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
How can i update the dependency?
As #Haroon #chrylis said, i checked the parent pom.xml and found <parent> configured in this pom.
<parent>
<groupId>insight.plat</groupId>
<artifactId>insight-bom-base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
in pom insight-bom-base, common 1.3.0-SNAPSHOT is configured, so web module depend this version not version 1.2.0-SNAPSHOT.
<dependencyManagement>
<dependency>
<groupId>com</groupId>
<artifactId>common</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependencyManagement>
As maven doc Transitive Dependencies shows,
Dependency management - this allows project authors to directly specify the
versions of artifacts to be used when they are encountered in transitive
dependencies or in dependencies where no version has been specified.
In the example in the preceding section a dependency was directly added to A even though
it is not directly used by A.
Instead, A can include D as a dependency in its dependencyManagement section and directly
control which version of D is used when, or if, it is ever referenced.
The parent dependencyManagement has higher priority than Transitive Dependencies, so in service module, it use common 1.2.0-SNAPSHOT
Related
Parent pom has dependencyManagement for spring-boot-dependencies version 2.5.4. Still I get this warning for child pom mvn build:
The POM for org.springframework.boot:spring-boot-starter-quartz:jar:2.5.4 is missing, no dependency information available
Declarations in <dependencyManagement> do nothing but being a template for the configuration once a dependency is used in <dependencies> later on.
I have the a project pom and a parent pom. The parent pom defines a dependency as follows:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.mycode/groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
My project pom inherits the parent and defines the dependency.
<parent>
<groupId>au.com.truelocal</groupId>
<artifactId>truelocal-parent</artifactId>
<version>develop</version>
</parent>
<dependencies>
<dependency>
<groupId>com.mycode</groupId>
<artifactId>common</artifactId>
</dependency>
</dependencies>
I used to build with Maven this way without issue.
I now want to start having a different version in parent, common and project.
I am going to use the maven versions plugin to set my version.
I am setting the parent version and version successfully however, maven keeps looking for the wrong version of common. E.g. if my project is building as version 1.0.0-4 then it looks for common-1.0.0-4 but I actually need it to get the latest version of common instead which could be for example 1.0.0-23.
Can i use the versions plugin to adjust my dependency version? How do I make it only apply to common and not other dependencies I may have?
mvn versions:set (I guess this is what you've done) sets the version of your project, respectively the project versions which are part of a multi module project.
It doesn't touch the versions of the dependencies, either they are configured in a parent pom within <dependencyManagement> or within <dependencies>.
You can adjust the dependency versions by several ways: mvn versions:display-dependency-updates , mvn versions:use-latest-releases , mvn versions:use-latest-snapshots.
Use mvn versions:help or mvn versions:help -Ddetail=true -Dgoal=use-latest-snapshots to get more informations.
I have two projects I am working on which share some common code - I am putting this common code in to a new project called Core.
Both my projects use maven to build, and my core classes will also use maven. In Eclipse how do I configure maven to do a maven build of the core classes and then use these in the build for my two other applications?
Is there some prebuilt rule I need to specify - for example build this project, however, go build core first and use the output of that for this.
Hope that makes some sort of sense.
You can add a dependency to Core artifact in your project.
If you use M2E Eclipse plug-in, workspace artifacts are quite easy to reference in the Maven editor.
The only condition for this kind of dependency to work is that dependent artifact must be retrievable from a maven repository (eventually putting it to the local maven repository through install goal).
You could add a parent pom, with modules
<project>
<groupId>com.mypackage</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<packaging>pom</packaging>
...
<modules>
<module>Core</module>
<module>MyModuleA</module>
<module>MyModuleB</module>
</modules>
...
</project>
And then just add your dependency in MyModuleA and MyModuleB like a normal dependency
<dependency>
<groupId>com.mypackage</groupId>
<artifactId>Core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I have 2 projects, A and B. B is a lib project and A reference to B.
When I add new function to B, it's ok to run mvn install on B, but it failed on mvn install on A due to can not find the symbol from new B.
I'm sure I did install correctly on project B, but why A still failed to compile and install?
This is A's pom.xml:
<dependency>
<groupId>A and B's group</groupId>
<artifactId>B</artifactId>
<scope>provided</scope>
</dependency>
any clue? Thanks
I would suggest to create a multi-module build like the following:
+-- root
+-- pom.xml
+-- module-A
+-- module-B
In the root pom you need to define the modules like this and define the packaging to pom.
<modules>
<module>module-A</module>
<module>module-B</module>
</modules>
Furthermore you can define a dependency of module-A to module -B simply by:
<project ..
<parent>
<groupId>project.parent</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module-A</artifactId>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module-B</artifactId>
<version>${project.version}</version>
</dependency>
..
</dependencies>
..
</project>
With this setup you can simply build all modules from the root folder just by:
mvn clean package
or you can import that structure into Eclipse (m2e installed?) or any other IDE like IntelliJ or Netbeans.
Try mvn clean install to do a totally fresh build of A, or mvn -U install to force Maven to look for updated snapshots. It sounds like your environment is still using the older JAR. It's hard to tell what your setup is from this description -- sounds like you're correctly installing B to your local repository, but I'm not sure if your IDE might be trying to be 'helpful' as well.
You can include the <version> element in the project's as well as dependency's declaration.
pass a version variable from Maven command line. Eg: ${build.version}
Module A's pom.xml:
<groupId>A & B's Group ID</groupId>
<artifactId>A</artifactId>
<version>${build.version}</version>
<dependencies>
<dependency>
<groupId>A & B's Group ID</groupId>
<artifactId>B</artifactId>
<version>${build.version}</version>
<type>war</type>
<scope>provided</scope>
</dependency>
...
So, whenever Project B is built and installed, the dependency will be available in the local maven repository for that particular version and will be picked by Project A
I'm trying to set up a multi-module Maven project, and the inter-module dependencies are apparently not being set up correctly.
I have:
<modules>
<module>commons</module>
<module>storage</module>
</modules>
in the parent POM (which has a packaging-type pom)
and then subdirectories commons/ and storage/ which define JAR poms with the same name.
Storage depends on Commons.
In the main (master) directory, I run mvn dependency:tree and see:
[INFO] Building system
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] domain:system:pom:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] Building commons
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
...correct tree...
[INFO] ------------------------------------------------------------------------
[INFO] Building storage
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
Downloading: http://my.repo/artifactory/repo/domain/commons/1.0-SNAPSHOT/commons-1.0-SNAPSHOT.jar
[INFO] Unable to find resource 'domain:commons:jar:1.0-SNAPSHOT' in repository my.repo (http://my.repo/artifactory/repo)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) domain:commons:jar:1.0-SNAPSHOT
Why does the dependency on "commons" fail, even though the reactor has obviously seen it because it successfully processes its dependency tree? It should definitely not be going to the 'net to find it as it's right there...
The pom for storage:
<?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>
<packaging>jar</packaging>
<parent>
<artifactId>system</artifactId>
<groupId>domain</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>domain</groupId>
<artifactId>storage</artifactId>
<name>storage</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- module dependencies -->
<dependency>
<groupId>domain</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- other dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Thanks for any suggestions!
(Edit)
To clarify, what I am looking for here is this: I don't want to have to install module X to build module Y which depends on X, given that both are modules referenced from the same parent POM. This makes intuitive sense to me that if I have two things in the same source tree, I shouldn't have to install intermediate products to continue the build. Hopefully my thinking makes some sense here...
As discussed in this maven mailing list thread, the dependency:tree goal by itself will look things up in the repository rather than the reactor. You can work around this by mvn installing, as previously suggested, or doing something less onerous that invokes the reactor, such as
mvn compile dependency:tree
Works for me.
I think the problem is that when you specify a dependency Maven expects to have it as jar (or whatever) packaged and available from at least a local repo. I'm sure that if you run mvn install on your commons project first everything will work.
Bonusing off the answer from Don Willis:
If your build creates test-jars to share test code among your reactor submodules you should use:
mvn test-compile dependency:tree
which will allow dependency:tree to run to completion in this case.
Realizing this is an older thread but it seems that either the tool evolved or this might have been missed the first time around.
It is possible to perform a build that makes dependencies resolved without installing by doing a reactor build.
If you start your build in the parent that describes the module structure of your project then your dependencies between your modules will be resolved during the build itself through the internal Maven reactor.
Of course this is not the perfect solution since it does not solve the build of a single individual module within the structure. In this case Maven will not have the dependencies in his reactor and will bee looking to resolve it in the repository. So for individual builds you still have to install the dependencies first.
Here is some reference describing this situation.
The only thing that workd for me : switching to gradle :(
I have
Parent
+---dep1
+---war1 (using dep1)
and I can just cd in war1 and use mvn tomcat7:run-war.
I always have to install the whole project before, despite war1 references his parent and the parent references war1 and dep1 (as modules) so all dependencies should be known.
I don't understand what the problem is.
In a Maven module structure like this:
- parent
- child1
- child2
You will have in the parent pom this:
<modules>
<module>child1</module>
<module>child2</module>
</modules>
If you now depend on child1 in child2 by putting the following in your <dependencies> in child2:
<dependency>
<groupId>example</groupId>
<artifactId>child1</artifactId>
</dependency>
You will receive an error that the JAR for child1 cannot be found. This can be solved by declaring a <dependencyManagement> block including child1 in the pom for parent:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>example</groupId>
<artifactId>child1</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
child1 will now be build when you run a compile or package etc. goal on parent, and child2 will find child1's compiled files.
for me, what led me to this thread was a similar problem and the solution was to ensure all module dependency pom's had
<packaging>pom</packaging>
the parent had
pom
my model dep had pom - so there was no jar to be found.
Using version >= 3.1.2 of the dependency plugin seems to solve the issue.
Make sure the module which is failing gets resolved in the pom, is pointing to the right parent by including the configurations in the pom file of the module.