failed to resolve dependencies in maven multi module project - java

I am posting this question even though there are other questions on this. However, I did not find any solution so far on this, hence posting this question.
I am getting this error :
Could not resolve dependencies for project vehicle-tracker:vehicle-simulator:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Could not find artifact vehicle-tracker:vehicle-tracker:pom:0.0.1-SNAPSHOT
common-libs jar is available under
.m2\repository\vehicle-tracker\common-libs\0.0.1-SNAPSHOT
The project I am trying to build is dependent over common-libs jar but maven is failed to find in local maven repo.
I am attaching following POM.xml
Parent.xml
<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>vehicle-tracker</groupId>
<artifactId>vehicle-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>common-libs</module>
<module>vehicle-simulator</module>
<module>tracker-dashboard</module>
</modules>
</project>
Common-libs 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>
<parent>
<groupId>vehicle-tracker</groupId>
<artifactId>vehicle-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../vehicle-tracker</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>common-libs</artifactId>
<name>common-libs</name>
<description>Common libraries for vehicle tracker</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
vehicle-simulator 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>
<parent>
<groupId>vehicle-tracker</groupId>
<artifactId>vehicle-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../vehicle-tracker/</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>vehicle-simulator</artifactId>
<name>vehicle-simulator</name>
<description>vehicle simulator for application</description>
<properties>
<java.version>1.8</java.version>
<swagger-version>2.9.2</swagger-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<artifactId>common-libs</artifactId>
<version>0.0.1-SNAPSHOT</version><!--${project.version}-->
<groupId>vehicle-tracker</groupId><!-- ${project.groupId} -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I am not able to find where I am doing mistake in POM or else where ...so not able to build project vehicle-tracker.

I resolved the build error. Actually I was putting below in common-libs module's POM.xml :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
This should be in the POM.xml of commons-lib module as it is creating spring-boot jar. Hence dependency was not available for dependent module.
After removing this block of configuration in POM.xml from commons-lib module, I am able to build the project without any issue(s).
Thank U All for looking in to this.
Just sharing this if any one having would face this knowingly or unknowingly.

Related

Unable to use classes from local maven dependency project [duplicate]

This question already has an answer here:
Add spring boot maven project as dependency to another project (locally)
(1 answer)
Closed 1 year ago.
I have two maven projects Microseed and Demo. I have added Microseed as dependency in Demo project but I am unable to use any classes from Microseed. weird thing is those classes appear in intelliJ's suggestion but I get compilation error as:
package com.example.microseed.security does not exist
Microseed/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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>microseed</artifactId>
<version>1.0.0</version>
<name>microseed</name>
<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<commons-lang3-version>3.4</commons-lang3-version>
<commons-collection-version>4.4</commons-collection-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- apache commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collection-version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Demo/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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>microseed</artifactId>
<version>1.0.0</version>
</dependency>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Both projects are in different directories
I have run mvn clean install in microseed
I am able to see microseed in local m2 repo
I am also able to see microseed in external libraries section
Any help in this regard will be highly appreciated.
If you use the parent spring-boot-starter-parent, AFAIK the JAR cannot be used as dependency.

How to build a multi-module Maven project without a main class in one of the modules

I've been trying to find an answer to this issue in similar questions but I still don't know what is causing it.
I have a multi-module maven project and I'm trying to run mvn install or mvn package and I get the following error
[INFO] app ................................................... SUCCESS
[ 1.025 s]
[INFO] module-data ..................................... FAILURE [
0.952 s]
[INFO] module-app ...................................... SKIPPED
[ERROR] Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage
(repackage) on project project-data: Execution repackage of goal
org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage
failed: Unable to find main class -> [Help 1]
The project-app module has a java class in the src folder, whereas the project-data module does not have a main class.
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>
<packaging>pom</packaging>
<modules>
<module>project-data</module>
<module>project-app</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>app</name>
<description></description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
project-data 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">
<parent>
<artifactId>app</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-data</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
project-app 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">
<parent>
<artifactId>app</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-app</artifactId>
<dependencies>
<dependency>
<artifactId>project-data</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I have something very similar to the structure of this project (sfg-pet-clinic), however, after downloading and running mvn package, it works fine. I don't see much difference between the pom files of my project and this one so what could I be missing?
Configuration is for older versions of spring.
Remove:
<configuration>
<skip>true</skip>
</configuration>
Instead, add this flag below pom artifactId
<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
Like so:
<parent>
<artifactId>mc-pet-clinic</artifactId>
<groupId>guru.springframework</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pet-clinic-data</artifactId>
<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
...
I would move the entire
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
section from the parent to the module-app module, because that one is the single module which uses the repackage functionality.
Moreower I would delete the plugin section from the module-data too, because there is no need to repackage that module.
Thanks to #wemu on the comments section.
Adding this:
<configuration>
<mainClass> ${your.start.Class}</mainClass>
</configuration>
to the plugin section is required on version 2.1.1.RELEASE of the spring-boot-starter-parent dependency, as long as your class is in another module.
The project sfg-pet-clinic I referred to in my question uses an older version which does not need the <mainClass> configuration
Okay here is how I fixed that.
My Steps were:
Change the packaging of pom.xml file for project-data to pom from
jar (I used overview of Eclipse)
add <type>pom</type> in pom.xml file for project-app for dependency of module-data
<dependency>
<groupId>samee.springframework</groupId>
<artifactId>project-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
Then you can run your clean and package/install
I just changed the Spring Boot version in the parent pom.xml from 2.1.1 to 2.0.3 and it works.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
Would be better to make it work in 2.1.1 though, but that's a quick and simple solution.

Spring Boot Maven Plugin isn't being recognized in Plugin Tags

I'm trying to install the spring boot maven plugin and it doesn't seem to be working. The error comes with the build tags. Intellij isn't recognizing 'sprint-boot-maven-plugin' inside the plugin tag and I'm not sure why. Intelli recognizes i in a dependency tag, but they aren't allowed inside the build tags. Please Help!
<?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.springframework</groupId>
<artifactId>gs-spring-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.6.RELEASE</version>
</plugin>
</plugins>
</build>
Dependency tag should be inside <dependencies> tag, not <project>:
...
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
</dependencies>
<properties>
...

How to move all the common dependencies from maven module into parent module in spring boot

I have two simple Spring Boot applications, one is a eureka-server and another is an eureka-client. Both of them reside in a maven aggregator module eureka-sample.
I have some common dependencies in both the eureka-server and eureka-client applications that I would like to move up to the parent pom so that I do not have to include them in each of the child modules every now and then.
I tried moving the dependency spring-boot-starter-test from the child modules into the parent pom under <dependencyManagement> section but then the tests in the child module were not able to compile as those classes were not able to find the jar. May be I misconfigured or placed it under wrong section.
How can I achieve this?
eureka-sample (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.study.spring</groupId>
<artifactId>eureka-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>eureka-sample</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR4</spring-cloud.version>
</properties>
<modules>
<module>eureka-server</module>
<module>eureka-client</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath />
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
eureka-server/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>
<artifactId>eureka-server</artifactId>
<packaging>jar</packaging>
<name>eureka-server</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.study.spring</groupId>
<artifactId>eureka-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
**<!-- ALL THE FOLLOWING 3 DEPENDENCIES SHOULD GO TO PARENT POM SO THAT I DO NOT HAVE TO PUT THEM IN EVERY CHILD MODULE -->**
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
eureka-client/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>
<artifactId>eureka-client</artifactId>
<packaging>jar</packaging>
<name>eureka-client</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.study.spring</groupId>
<artifactId>eureka-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
**<!-- ALL THE FOLLOWING 3 DEPENDENCIES SHOULD GO TO PARENT POM SO THAT I DO NOT HAVE TO PUT THEM IN EVERY CHILD MODULE -->**
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Try putting the common dependencies inside the <dependencies> section of the parent .pom instead of the <dependencyManagement> section.
With <dependencyManagement> you only prepare and configure the dependencies for all children modules, but in order to actually use them, you'll still need to reference them from within the child module.
The difference is subtle, but important - see https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html for details.

package does not exist mvn clean install

I'm working on a multi module maven project with this structure :
ats-parent has 3 children : ats-api, ats-client, ats-impl
ats-impl has 4 children: ats-accountManager, ats-common, ats-noticeManager, ats-applicationContext.
moreover ats-common depends on ats-api.
So here is my problem :
when I try to run mvn clean install i have the error :
/home/frozen/workspace/ATS/ats-parent/ats-impl/ats-common/src/main/java/com/o2xp/ats/common/services/ti/CategoryService.java:[5,31] package com.o2xp.ats.api.common does not exist
I precise that CategoryService which is ats common uses some classes into ats-api. Moreover i checked the detailed log and i refers to the lines corresponding to the imports of classes from the api module
Here is the pom of ats-common :
<?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>
<artifactId>ats-impl</artifactId>
<groupId>com.o2xp</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<artifactId>ats-common</artifactId>
<name>ats-common</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.o2xp</groupId>
<artifactId>ats-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
the pom of ats-api :
<?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>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.o2xp.ats.accountManager.App</start-class>
</properties>
<parent>
<groupId>com.o2xp</groupId>
<artifactId>ats-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<groupId>com.o2xp</groupId>
<artifactId>ats-api</artifactId>
<name>ats-api</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
and the pom of ats-impl :
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>pom</packaging>
<groupId>com.o2xp</groupId>
<artifactId>ats-impl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ats-impl</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.3.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>io.github.jhipster</groupId>
<artifactId>jhipster</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies>
<modules>
<module>ats-application-context</module>
<module>ats-notice-manager</module>
<module>ats-common</module>
<module>ats-accountManager</module>
</modules>
</project>
the other modules are compiled except ats-accountManager which is skipped because it is after ats-common.
package com.o2xp.ats.api.common belongs to your api module.
Change
<modules>
<module>ats-application-context</module>
<module>ats-notice-manager</module>
<module>ats-common</module>
<module>ats-accountManager</module>
</modules>
to
<modules>
<module>ats-application-context</module>
<module>ats-notice-manager</module>
<module>ats-accountManager</module>
</modules>
ats-common module will be build by ats-api module
I found the solution in my ats-parent pom i had added spring boot as a parent i just removed this and it's working

Categories