<project (...)>
<modelVersion>4.0.0</modelVersion>
<groupId>our.group.id</groupId>
<artifactId>parent.of.all</artifactId>
<version>3.2.2-SNAPSHOT</version>
<packaging>pom</packaging>
<url>http://maven.apache.org</url>
<modules>
<module>module-common</module>
<module>module-A</module>
<module>module-B</module>
<module>module-C</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-B</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-C</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
This is the main pom of project, that holds within some modules module-common module-A module-B module-C.
The issue that I am facing is the fact, that most of them is bing compiled and tested multiple times, because of internal dependencies between modules:
<project (...)>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>our.group.id</groupId>
<artifactId>parent.of.all</artifactId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<artifactId>module-B</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency> <!-- internal dependency to other module -->
<groupId>our.group.id</groupId>
<artifactId>module-common</artifactId>
</dependency>
</dependencies>
</project>
The more dependencies there are, the longer it takes to build project. How can I prevent maven from doing full install on the same modules being done multiple times?
Related
1:I have a parent project
it`s pom.xml below
...
<modules>
<module>first</module>
<module>second</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
2:create first module
it's pom.xml below
...
<parent>
<artifactId>parent</artifactId>
<groupId>com.ppf.demo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>first</artifactId>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</project>
I want Seata 1.2.0.
because spring-cloud-starter-alibaba-seata has default Seata 1.1.0,so I exclude seata-spring-boot-starter and <dependency> Seata 1.2.0 myself
first module dependency -- Seata 1.2.0
3:create second module and has dependency first module
it's pom.xml below
...
<parent>
<artifactId>parent</artifactId>
<groupId>com.ppf.demo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>second</artifactId>
<dependencies>
<dependency>
<groupId>com.ppf.demo</groupId>
<artifactId>first</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
4:Question
Why my second module is still has Seata 1.1.0,not 1.2.0
second module dependencies
So here is the scenario,
I am trying to compile a maven project which have some persistent classes. I have persistence.xml under src\main\resources\. This compiles fine, but I get run-time error for persistence not found which can be easily resolved if I manually move persistence.xml under META-INF dir of jar(xml file is packaged under root of the jar).
Now if I move persistence.xml under src\main\resources\META-INF I get weird compile-time error of
Fatal error compiling: java.lang.RuntimeException:
javax.annotation.processing.FilerException: Attempt to recreate a file
for type my.package.EntityClassName_
This EntityClassName can be any one of my Entity class.
I just want to package persistence.xml under META-INF directory of jar.
Can someone point out what am I missing?
I am using maven compiler source and target as 1.6 if it matters.
EDIT: This project have a parent maven project.
<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.some.domain</groupId>
<artifactId>p-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>m1</module>
<module>m2</module>
<module>m3</module>
</modules>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<scm>
<connection>scm:git:https://some.place/project.git</connection>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.1.0.6.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
pom of this project
<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>
<parent>
<groupId>com.some.domain</groupId>
<artifactId>p-parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>m2</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
</dependency>
</dependencies>
</project>
It was solved bu using -proc:none as compiler argument.
I have a problem with building a project Farma-rest which depends on my other project Farma. I put dependency in my pom.xml but it couldn't resolve dependencies for the project. It shows me this error message:
Failed to execute goal on project Farma-rest: Could not resolve dependencies for project sk.upjs.ics:Farma-rest:jar:1.0-SNAPSHOT: Could not find artifact sk.upjs.ics:Farma:jar:1.0-SNAPSHOT -> [Help 1]
Here is the pom of the first 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">
<modelVersion>4.0.0</modelVersion>
<groupId>sk.upjs.ics</groupId>
<artifactId>Farma</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.8-dmr</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
<scope>test</scope>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<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>
</project>
And here is the POM of the project which I want to build:
<?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>sk.upjs.ics</groupId>
<artifactId>Farma-rest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.8-dmr</version>
</dependency>
<dependency>
<groupId>sk.upjs.ics</groupId>
<artifactId>Farma</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- <scope>compile</scope>-->
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.3</version>
</dependency>
</dependencies>
</project>
I tried to clean and build the project but it didn't helped.
The jar for the Farma project is not available in your local maven repo.
Check if the ~/.m2/repository/sk.upjs.ics/Farma/1.0-SNAPSHOT directory exists. It should not at this point.
Run the build for the Farma project. Maven should create the artifact and put it in your local maven repository.
Check the same directory as before. It should now exist and it should have a jar and pom in it.
Now try building Farma-rest again and it should work.
my maven project has multiple maven modules. Two of those modules (product and feature) are dependent on each other. When I include the modules as dependencies in the pom files, an ! mark appears on the modules. On running maven install I get this error.
The projects in the reactor contain a cyclic reference: Edge between
'Vertex{label='com.catalog:feature:0.0.1-SNAPSHOT'}' and
'Vertex{label='com.catalog:product:0.0.1-SNAPSHOT'}' introduces to
cycle in the graph com.catalog:product:0.0.1-SNAPSHOT -->
com.catalog:feature:0.0.1-SNAPSHOT --> com.catalog:product:0.0.1-
SNAPSHOT #
Without adding the dependencies Product can't access functions defined in Feature module and vice versa.
The parent 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>
<groupId>com.catalog</groupId>
<artifactId>catalog</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.enterprise</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
<modules>
<module>category</module>
<module>resource</module>
<module>hibernate</module>
<module>product</module>
<module>helper</module>
<module>feature</module>
</modules>
Product module pom.xml
<?xml version="1.0"?>
<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>
<parent>
<groupId>com.catalog</groupId>
<artifactId>catalog</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>product</artifactId>
<name>product</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>hibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>category</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>helper</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>feature</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Feature module pom.xml
<?xml version="1.0"?>
<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>
<parent>
<groupId>com.catalog</groupId>
<artifactId>catalog</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.catalog</groupId>
<artifactId>feature</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>feature</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>hibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.catalog</groupId>
<artifactId>product</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Design smell.
Refactor your modules. Basically everything which is needed in both modules should go into a common dependency. You cannot have cycles in your dependency tree, it just won't work.
Update: As this answer is occasionally getting a new upvote, I wanted to mention: the "tree" in "dependency tree" refers to a tree from graph theory, which means that by definition you cannot have cycles :)
It may not work for your particular situation but another option to rectify cyclical dependencies is to use events.
First, set your modules up in a tree with no cyclical dependencies. Put your Event classes at the top of the tree. Then publish and listen for events in any of the modules. This allows you to have modules that communicate with each other without depending on each other.
For how to publish and listen for events in Spring see:
https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2
I have been implementing an application using Spring Boot with the following Maven hierarchy.
pom.xml
pom.xml [core module]
pom.xml [batch module]
The idea behind that structure is as follows: The root pom contains only common libraries, the core pom specifies to package as jar file, and the batch pom use the core for computing some specific tasks. (I have put my pom.xml of those files in the end, too.)
However, when I execute my batch module using the following command:
mvn spring-boot:run
I got the following error.
[ERROR] Failed to execute goal on project batch-owl:
Could not resolve dependencies for project io.github.xlives:batch-owl:jar:0.1.0:
Failure to find io.github.xlives:core:jar:0.1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository,
resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1][ERROR]
Parent pom.xml
...
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.xlives</groupId>
<artifactId>jSimPi</artifactId>
<packaging>pom</packaging>
<version>0.1.0</version>
<modules>
<module>core</module>
<module>batch-owl</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>edu.stanford.protege</groupId>
<artifactId>org.semanticweb.owl.owlapi</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
... End
Core pom.xml
...
<parent>
<artifactId>jSimPi</artifactId>
<groupId>io.github.xlives</groupId>
<version>0.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<version>0.1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
... End
Batch pom.xml
...
<parent>
<artifactId>jSimPi</artifactId>
<groupId>io.github.xlives</groupId>
<version>0.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>batch-owl</artifactId>
<dependencies>
<dependency>
<groupId>io.github.xlives</groupId>
<artifactId>core</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
</dependencies>
... End
I am still practicing Maven. Please tell me if you have any concerns on my code.
Thanks :