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.
Related
I am writing a package (PACK-A) that is consumed by another (PACK-B). For local development I want to use a local jar that is produced from PACK-A and use it in PACK-B.
The workflow would be
cd PACK-A; mvn clean; mvn package
cd PACK-B; mvn clean; mvn package (but pulls in the local PACK-A jar file)
I thought the way to do it was through the <repositories /> tag in the pom.xml file so my POM.xml file looks like this (lots taken out for brevity):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.team</groupId>
<artifactId>PACK-B</artifactId>
<version>1.0.0</version>
<dependencies>
<groupId>com.company.team</groupId>
<artifactId>service-name</artifactId>
<version>0.3.0-master+17</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>service-name</id>
<url>file:///Users/username/Projects/service-name/target</url>
</repository>
</repositories>
</project>
file:///Users/username/Projects/service-name/target is the directory that compiles (mvn package) the service.jar.
It isn't picking it up and I've confirmed it using a decompiler. How do I get maven to use my local jar in the service that I compiled? Or is my <url> directory written out incorrectly?
Also, I've confirmed, via the decompiler, that the service does compile with my changes. It just isn't picked up by my consumer.
For local development I want to use a local jar that is produced from PACK-A and use it in PACK-B.
To achieve this, you "only need":
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.team</groupId>
<artifactId>PACK-B</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.company.team</groupId>
<artifactId>PACK-A</artifactId>
<!-- same version, or which ever suits you -->
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
And to run mvn install (which additionally to package installs the artifact into the local repository).
See also: How to build dependent project when building a module in maven
and What does mvn install in maven exactly do
It is a "complex field" (multi-module...), but the thing You are trying to achieve is really simple/101.
I'm having difficulty building a spring boot application from within a Dockerfile on Linux.
It works just fine on Windows.
I've seen other posts where folks say I should specify or remove the relativePath in the pom.xml file, but I don't think that's the issue nor did it work.
Here's my error, followed by my code:
> Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom and 'parent.relativePath' points at no local POM # line 6, column 13
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT (/home/app/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom and 'parent.relativePath' points at no local POM # line 6, column 13: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/199.232.196.215, repo.maven.apache.org/199.232.192.215] failed: Connection timed out (Connection timed out) -> [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
ERROR: Service 'web' failed to build: The command '/bin/sh -c /home/app/with-proxy.sh mvn -f /home/app/pom.xml clean test package' returned a non-zero code: 1
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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ciee</groupId>
<artifactId>stanfordcorenlp-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>stanfordcorenlp-server</name>
<description>Stanford Core NLP Server</description>
<properties>
<java.version>1.8</java.version>
</properties>
<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>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>4.0.0</version>
<classifier>models</classifier>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>4.0.0</version>
<classifier>models-english</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
docker-compose.yml
version: "3"
services:
web:
build:
context: ..
dockerfile: ./docker/Dockerfile.cambridge
image: stanfordcorenlp # (override the name Compose picks)
container_name: stanfordcorenlp
ports:
- "9000:9000"
networks:
- cieenetwork
networks:
cieenetwork:
external: true
Dockerfile:
# build stage
FROM maven:3.6.3-jdk-8 AS build
MAINTAINER Philips CIEE Team
ENV TZ=US/Central
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
COPY ./stanfordcorenlp-server/src /home/app/src
COPY ./stanfordcorenlp-server/pom.xml /home/app
RUN chmod -R 775 /home/app
RUN mvn -f /home/app/pom.xml clean test package
# Package stage
FROM openjdk:8-jdk-alpine
ENV TZ=US/Central
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
# set environment variable to log messages immediately
ENV PYTHONUNBUFFERED 1
# set environment variable to prevent Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE 1
COPY --from=build /home/app/target/*.jar app.jar
ENV PORT 9000
EXPOSE 9000
ENTRYPOINT ["java","-jar","app.jar"]
I had to set up maven proxy settings.
Maven proxy config
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.
In my maven project I need to use some local jar libraries as a dependency.
I'm trying to use this method to configure them in pom.xml:
<repositories>
<repository>
<id>projectName.local</id>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.myproject</groupId>
<artifactId>ProjectName</artifactId>
<version>1.0</version>
</dependency>
<!-- other dependencies... -->
</dependencies>
I defined a local repository that points to a libs folder into the project root. Then I placed the jars in this folder:
/libs/org/myproject/ProjectName/1.0/ProjectName-1.0.jar
But, building the project I'm getting this warning:
The POM for org.myproject:ProjectName:jar:1.0 is missing, no dependency information available
And this build failure result:
Failed to execute goal on project my_project: Could not resolve dependencies for project *** : The following artifacts could not be resolved: org.myproject:ProjectName:jar:1.0: Failure to find org.myproject:ProjectName:jar:1.0 in file://C:\Users\David\Documents\NetBeansProjects\my_project/libs was cached in the local repository, resolution will not be reattempted until the update interval of projectName.local has elapsed or updates are forced -> [Help 1]
What am I missing?
I think just copying the jar file will not solve your problem. You will need to install the dependency using Maven itself in that repository using a command like this one:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar \
-DlocalRepositoryPath=path-to-specific-local-repo
path-to-specific-local-repo should be the path to your local repository (file://${project.basedir}/libs).
Define the pom.xml like dependency.
<dependency>
<groupId>org.myproject</groupId>
<artifactId>ProjectName</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jarfile</systemPath>
</dependency>
Put the all the files in the folder
You can add your local jar as:
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>
Local works for you by doing above.If you want to pack this local jar in your fat jar then include following line in maven plugin configuration:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
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.