I’m trying to build a Docker image from my DockerFile but keep getting an error like it can't find the parent pom.xml to perform a maven command in the docker file and build the project.
Ive been looking around and you see what people do is the add to the child pom.xml a reference to the parent pom.xml y tried adding a relativePath>.. /pom.xml/relativePath> to the child but still won't work.
Maven-multimodule project
[
DockerFile
FROM alpine/git as clone
WORKDIR /app
RUN git clone https://github.com/RicardoVargasLeslie/manager.git
FROM openjdk:8-jdk-alpine as build
WORKDIR /workspace/app
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install -DskipTests
ENTRYPOINT ["java","-jar","/Web-0.0.1-SNAPSHOT.jar"]
Child-pom.xml(Web)
<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.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>Web</artifactId>
<name>Web</name>
<description>Web Module</description>
Parent-pom.xml(Core)
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Core</name>
<description>Core Module</description>
<packaging>pom</packaging>
Docker comand to build image
docker build -t rest-api .
Comand-line Trace
$ docker build -t rest-api .
Sending build context to Docker daemon 42.92MB
Step 1/11 : FROM alpine/git as clone
---> a1d22e4b51ad
Step 2/11 : WORKDIR /app
---> Using cache
---> e53f5b4941b5
Step 3/11 : RUN git clone https://github.com/RicardoVargasLeslie/manager.git
---> Using cache
---> 490b2afea22c
Step 4/11 : FROM openjdk:8-jdk-alpine as build
---> a3562aa0b991
Step 5/11 : WORKDIR /workspace/app
---> Using cache
---> 0b7c106319e9
Step 6/11 : COPY mvnw .
---> Using cache
---> 2c7ab0b79d25
Step 7/11 : COPY .mvn .mvn
---> Using cache
---> eb9ec36b737a
Step 8/11 : COPY pom.xml .
---> Using cache
---> 2296a5fbd6ae
Step 9/11 : COPY src src
---> Using cache
---> 022a609f4376
Step 10/11 : RUN ./mvnw install -DskipTests
---> Running in 897cff2e3c3b
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 5, column 10
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.imricki.manager:Web:[unknown-version] (/workspace/app/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM # line 5, column 10 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
The command '/bin/sh -c ./mvnw install -DskipTests' returned a non-zero code: 1
I’m not sure what wron or how to make the build work,thanks for any help.
Maven is a tool that enables a declarative way of managing your project's dependencies. It does that by standardising the way jar and pom files (artifacts) are shared by projects and uses maven coordinates to declare a project dependency (groupId, artifactId and version) which are then looked up in a large public maven repository of jar and pom files called Maven Central.
In order to have your jar/pom files (like your core for example) managed as a maven artifact, you need to deploy your artifact to either the Maven Central (public repository accessible by anyone) or a private repository some where in your private network (or even on the internet, and maybe with authentication). In the case of a private repository, you need to include the you private repository so that your maven execution not only looks for artifacts in Maven Central, but also in your private repository. You can achieve this by adding the following to your settings.xml file:
<!-- Authentication here -->
<servers>
<server>
<id>nexus</id>
<username>some_username</username>
<password>some_passowrd</password>
</server>
</servers>
...
<profiles>
<profile>
<id>nexus</id>
<!--Override the repository (and pluginRepository) "central" from the
Maven Super POM -->
<repositories>
<repository>
<id>nexus-release</id>
<name>nexus-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases</url>
</repository>
<repository>
<id>nexus-thirdparty</id>
<name>nexus-thirdparty</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin-release</id>
<name>nexus-plugin-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases/</url>
</pluginRepository>
<pluginRepository>
<id>nexus-plugin-third-party</id>
<name>nexus-plugin-third-party</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
...
I noticed your child pom.xml file references a custom parent module. You need to make sure that your parent module is in a maven repository (Nexus/Artifactory) and that you supply a settings.xml file with the repository settings for the Docker container to be able to pull the parent pom.
Related
I'm working on a project where we are analysing dependency relationships in artifacts from Maven Central. What I need to do is extract the dependencies as GraphML using org.apache.maven.plugins:maven-dependency-plugin:3.1.1:tree and for simple projects that's easy.
However, for projects which have <module> dependencies but no relativePath in the pom, I cannot get those dependencies resolved:
My example is the Apache Hivemind project pom, modules section:
<modules>
<module>framework</module>
<module>xml</module>
<module>annotations</module>
<module>library</module>
<module>jmx</module>
<module>examples</module>
</modules>
Which results in this output:
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.apache.hivemind:hivemind-project:2.0-alpha-1 (/data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom) has 6 errors
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/framework of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/xml of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/annotations of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/library of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/jmx of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
[ERROR] Child module /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/examples of /data/scratch/artifacts/org/apache/hivemind/hivemind-project/2.0-alpha-1/hivemind-project-2.0-alpha-1.pom does not exist
I do have all those dependencies downloaded into my local repo.
How do I invoke mvn so that I can get it to look in my local repo (or any repo I specify, for that matter) for the dependencies?
A colleague suggested that I try a slightly different approach: make the artifact in the POM a dependency in a new (temporary) POM.
So for org.apache.hivemind:hivemind-framework:2.0-alpha-1, construct a temporary POM as follows:
<?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>demo</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.hivemind</groupId>
<artifactId>hivemind-framework</artifactId>
<version>2.0-alpha-1</version>
</dependency>
</dependencies>
</project>
and then use that temporary POM as the -f argument.
TL/DR: How can I cache the pom.xml file's <parent> so my build can be run in offline mode?
I'm using Docker to build a maven project. My goal is to add two steps to the build: one to download all of the dependencies, and another to build the project. Here's what my Dockerfile looks like so far:
FROM maven:3.3-jdk-8
# Download the project dependencies (so they can be cached by Docker)
ADD pom.xml /runtime/
WORKDIR /runtime
RUN mvn dependency:go-offline
RUN mvn dependency:resolve-plugins
# Mount the local repository
ADD . /runtime
# Build the service
RUN mvn clean package -o -DskipTests
This seems to work fine for the plugins. I checked the /root/.m2/repository and everything seems to be in order.
Edit: When double checking for the /root/.m2/repository directory, it's no longer there. For some reason, Maven isn't saving any of the dependencies to this location.
Edit 2: After building the Docker image, there's no /root/.m2/repository directory. However, if I run mvn dependency:go-offline from within a shell inside the Docker container, the directory is created without a problem.
When I attempt build my application, I get the following error:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:service:1.2: Cannot access central (http://jcenter.bintray.com) in offline mode and the artifact org.springframework.boot:spring-boot-starter-parent:pom:1.4.0.M3 has not been downloaded from it before. and 'parent.relativePath' points at wrong local POM # line 14, column 13
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.sample:service:1.2 (/runtime/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.oe:graph-service:1.2: Cannot access central (http://jcenter.bintray.com) in offline mode and the artifact org.springframework.boot:spring-boot-starter-parent:pom:1.4.0.M3 has not been downloaded from it before. and 'parent.relativePath' points at wrong local POM # line 14, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
The problem seems to be that mvn dependency:go-offline isn't resolving the parent. When I run the build in offline mode, it breaks.
Here are the relevant portions of my pom.xml 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.M3</version>
</parent>
...
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>repository.springsource.snapshot</id>
<name>SpringSource Snapshot Repository</name>
<url>http://repo.springsource.org/snapshot</url>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.scala</groupId>
<artifactId>spring-scala_2.11</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- disabling Spring cloud AWS until proper testing harnesses can be set up -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-autoconfigure</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
...
</dependencies>
...
</project>
If you customize maven's settings.xml file you can save your repository files on image.
Create a custom version of settings.xml, with the localRepository setting modified, like this:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository -->
<localRepository>/usr/share/maven/repo</localRepository>
...
Then override the default configuration when building your image:
FROM maven:3-jdk-8
COPY settings.xml /usr/share/maven/conf/settings.xml
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app
RUN mvn dependency:go-offline
RUN mvn clean package
Now your repository is stored in /usr/share/maven/repo.
Using onbuild
You can also create a base image using ONBUILD, this will allow to have custom configured images for every maven project.
Like this:
FROM maven:3-jdk-8
COPY settings.xml /usr/share/maven/conf/settings.xml
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD ADD . /usr/src/app
ONBUILD RUN mvn dependency:go-offline
ONBUILD RUN mvn clean package
Then build the image:
docker build -t mvn_bldr .
This will create a template for other maven images. Then you can create your custom downstream image with:
FROM mvn_bldr
If you want to customize your image further you can add more instructions, every instruction of the template will be triggered after the FROM mvn_bldr command, as in the docs:
The trigger will be executed in the context of the downstream build,
as if it had been inserted immediately after the FROM instruction in
the downstream Dockerfile.
It may seem like using RUN with Docker is like executing commands in a shell script, but it's not. Every instance of RUN gets applied to a new container that results from the changes created by the previous command. So each command is executing inside of a new container context.
Dockerifles can contain a VOLUME reference, which mounts an external directory inside the Docker container. If there were any files inside the volume, those files are wiped out. If you don't explicitly specify a volume, Docker is happy to instead create an empty folder.
While my Dockerfile doesn't contain an explicit reference to a VOLUME, its parent does. So, even though my mvn dependency:go-offline command was running, those files were being wiped out in the next step by the VOLUME specified in the docker-maven Dockerfile.
In the end, I couldn't find a good way to make the maven Docker image work, so I switched to the openjdk image and installed maven via apt-get instead.
I have this weird situation. I have an spring boot application and in that application there are some legacy jars were needed to run the application. mvn does not allow to have a lib folder. So I added the jars to the local maven repository.
This worked well (Till there are no repositories declared in the pom file) till I wanted to add, spring-batch-admin.version 2.0-BUILD-SNAPSHOT, to my project.
So, when I added this,
<repository>
<id>spring-snapshots-local</id>
<name>Spring Maven Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot-local/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
I get good amount of Missing artifact, and also when I tried to run mvn install in command line, i get,
[ERROR] Failed to execute goal on project webapp: Could not resolve dependencies for project com.ccc.cccc-tool:webapp:war:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ccj:CCjJDBC:jar:1.0: Failed to read artifact descriptor for com.ccj:CCjJDBC:jar:1.0: Could not transfer artifact com.ccc:CCjJDBC:pom:1.0 from/to spring-snapshots-local (https://repo.spring.io/libs-snapshot-local/): Failed to transfer file: https://repo.spring.io/libs-snapshot-local/com/ccj/CCjJDBC/1.0/CCjJDBC-1.0.pom. Return code is: 409 , ReasonPhrase:Conflict. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I am not think of uploading these legacy jars to the maven central to get this to working. What am I doing wrong here.
Try to add the local repository into your project. For example, your have a jar file
group: com.packagename
artifactId: somejarfile
version: 2.0.0b
Then add this code into your pom.xml file:
<repositories>
<repository>
<id>localDependenciesRepo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/src/main/resources/localDependenciesRepo</url>
</repository>
</repositories>
Then create a folder for this repository src/main/resources/localDependenciesRepo. Create a folder structure for the library: com -> packagename -> somejarfile -> 2.0.0b. "->" means new folder of course.
And put your jar file into this folder.
Don't forget to copy/create pom.xml file for your jar file. As example:
<?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>
<groupId>com.packagename</groupId>
<artifactId>somejarfile</artifactId>
<version>2.0.0b</version>
</project>
At least I use this solution and it works perfectly.
Using eclipse maven and java 1.7 I have designed two backends named webservice.staff.backend and webservice.webuser.backend .
Now There is another webservice which is written by some of our Senior Team Member, which is a another module for Project shared with me by git.
In this New Project in pom.xml there are two local project dependency have been added as Follows.
<dependency>
<groupId>webservice.staff.backend</groupId>
<artifactId>webservice.staff.backend</artifactId>
<version>1.0.0</version>
<classifier>classes</classifier>
<type>jar</type> //used jar but webservices packaging as a war
</dependency>
<dependency>
<groupId>webservice.webuser.backend</groupId>
<artifactId>webservice.webuser.backend</artifactId>
<version>1.0.0</version>
<classifier>classes</classifier>
<type>jar</type> // used jar but webservices packaging as a war
</dependency>
but these dependency is not resolved when I am just trying to perform Maven clean install. What I Found in my earlier webservice Projects are packaging as a WAR but here used as jar
Here is earlier Project packaging type in pom.xml.
<groupId>webservice.staff.backend</groupId>
<artifactId>webservice.staff.backend</artifactId>
<packaging>war</packaging> //packaged as war but used as jar??
<groupId>webservice.webuser.backend</groupId>
<artifactId>webservice.webuser.backend</artifactId>
<packaging>war</packaging> //packaged as war but used as jar in
/*I Have also Changed packaging as a jar and then clean Install
and try to build the New Project but error still the same. */
Error StackTrace
[ERROR] Failed to execute goal on project webservice.credit.backend: Could not resolve dependencies for project webservice.credit.backend:webservice.credit.backend:war:2.0.0: The following artifacts could not be resolved: webservice.staff.webservice.staff.backend:jar:classes:1.0.0, webservice.webuser.backend:webservice.webuser.backend:jar:classes:1.0.0: Failure to find webservice.staff.backend:webservice.staff.backend:jar:classes:1.0.0 in http://download.java.net/maven/2/ was cached in the local repository, resolution will not be reattempted until the update interval of Java.Net has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Note :- I have tried so many ways and also so many answers on stackOverflowin this regard but no one gives me correct solution to that.
Please Help anybody to Resolve this.. Thanks.
Remove <classifier>classes</classifier>
<dependency>
<groupId>webservice.staff.backend</groupId>
<artifactId>webservice.staff.backend</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>webservice.webuser.backend</groupId>
<artifactId>webservice.webuser.backend</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>
pom will be same for both projects except packaging will be jar :
<groupId>webservice.staff.backend</groupId>
<artifactId>webservice.staff.backend</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<groupId>webservice.webuser.backend</groupId>
<artifactId>webservice.webuser.backend</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
Make sure your settings.xml is like below :
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
------
</settings>
I have uploaded sample here.
Finally !!!
Got the solution for this.
what i need to do during clean & install add extra param with mvn to export the class files. parameter ==> -Dattach.and.archive.classes=true to the mvn command.
mvn clean install -Dattach.and.archive.classes=true //added one extra param
// -Dattach.and.archive.classes=true solved my dependency Problem.
Note :- If you Defined in pom.xml Project packaging as war and want a jar as dependency in Your local maven Repository. Just put this extra Option with -Dattach.and.archive.classes=true with mvn.
I can't seem to get Maven to find a sibling's module in a multi-module project.
I've run mvn clean install in all modules.
Here's the setup:
Product
+-- MagniCompCommon
+-- Model
The Model project has MagniCompCommon as a dependency. When I run mvn clean compile in Model, I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Model 1.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.magnicomp:MagniCompCommon:jar:1.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.585 s
[INFO] Finished at: 2015-10-14T10:09:04-07:00
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Model: Could not resolve dependencies for project com.magnicomp:Model:jar:1.0: Failure to find com.magnicomp:MagniCompCommon:jar:1.0 in http://download.java.net/maven/2/ was cached in the local repository, resolution will not be reattempted until the update interval of Java.Net has elapsed or updates are forced -> [Help 1]
As you can see, Maven is trying to find MagniCompCommon in the java.net repo (this is the first repository entry in the parent (Product) pom.xml).
Here is Product 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>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>MagniCompCommon</module>
<module>Model</module>
<module>Common</module>
<module>Agent</module>
<module>Doc</module>
</modules>
... snip ...
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
Here is MagniCompCommon 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>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
</parent>
<!-- <groupId>com.magnicomp.common</groupId> -->
<artifactId>MagniCompCommon</artifactId>
<packaging>jar</packaging>
Here is Model pom.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>
<parent>
<groupId>com.magnicomp</groupId>
<artifactId>Product</artifactId>
<version>1.0</version>
</parent>
<artifactId>Model</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.magnicomp</groupId>
<artifactId>MagniCompCommon</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
When you are building a multi-module Maven project, you need to run Maven commands from the root POM. This means you need to run mvn clean install on Product's pom.xml.
The error you are getting is expected: you are only building Model. In Model's POM, Maven sees that there is a dependency on MagniCompCommon so it tries to look for that dependency. First, it searches in your local repo: it fails to find it there since you did not install MagniCompCommon before. As a result, it looks for it in the predefined remote repositories (and also fails to find it).
You would be able to circumvent this by first running mvn clean install on MagniCompCommon's POM, then on Model POM but this is much easier done by invoking Maven directly on the root POM. It will correctly build every modules in the right order (since Model depends on MagniCompCommon, it will build MagniCompCommon first, then Model).
As a side note, you can remove the line <packaging>jar</packaging> because this is the default.
I noticed MagniCompCommon pom doesnt specify a version
<!-- <groupId>com.magnicomp.common</groupId> -->
<artifactId>MagniCompCommon</artifactId>
<packaging>jar</packaging>
And in Product pom, you're referencing version 1.0
<dependency>
<groupId>com.magnicomp</groupId>
<artifactId>MagniCompCommon</artifactId>
<version>1.0</version>
</dependency>
Have you tried specifying version 1.0 in MagniCompCommon pom?