i am trying to build a docker for my Java Spring MVC application and packages are managed by MAVEN.
my project folder view:
1)wc-aws(JAR)
-pom.xml
-src
2)wc-admin(spring project WAR)
-pom.xml
-src
3)wc-dao(JAR)
-pom.xml
-src
-pom.xml
my DockerFile
FROM maven:3.6.1-jdk-8 as maven_builder
ENV HOME=/app
RUN mkdir $HOME
WORKDIR $HOME
ADD . $HOME
RUN mvn dependency:go-offline
RUN mvn clean install -T 2C -DskipTests=true
FROM tomcat:8.5.43-jdk8
ENV HOME=/app
FROM tomcat:8.5.43-jdk8
COPY --from=maven_builder /app/wc-admin/target/wc-admin.war /usr/local/tomcat/webapps/ROOT
i get the following error :
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for wc-pom 1.0:
[INFO]
[INFO] wc-pom ............................................. SUCCESS [02:17 min]
[INFO] wc-commons ......................................... SUCCESS [02:56 min]
[INFO] wc-dao ............................................. FAILURE [ 13.308 s]
[INFO] wc-aws ............................................. SKIPPED
[INFO] wc-event ........................................... SKIPPED
[INFO] wc-mqueue .......................................... SKIPPED
[INFO] wc-admin ........................................... SKIPPED
[INFO] wc-ftp-download .................................... SKIPPED
[INFO] wc-content-transformation .......................... SKIPPED
[INFO] wc-content-notification ............................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:59 min
[INFO] Finished at: 2019-07-26T07:48:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project wc-dao: Could not resolve dependencies for project com.whitecoats:wc-dao:jar:1.0: Could not find artifact com.whitecoats:wc-commons:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
As you can see, the error is saying that, maven is looking for wc-dao in central and cannot find it.
but wc-dao is local java project and its JAR file is created in runtime.
how do i resolve it?
The problem here is that when maven performs dependency:go-offline it looks for all dependencies including dependencies on the other modules in the project. But at the moment of running there are no built artifacts for the module-dependencies, because they have never been built. Read more here.
It is a known issue, at the same time, there is no solution except building the dependent modules first.
But in your particular case it is not possible (once you build the dependencies the command can't be cached by Docker).
A workaround: The dependency plugin has an option called excludeArtifactIds using which you can exclude some of the modules that do require modular dependencies. Having this, you will be able to resolve all dependencies except of those in the excluded modules.
mvn dependency:go-offline -DexcludeArtifactIds:wc-dao,some-other-artifact
The same way you can use excludeGroupIds if you want to exclude a group.
Of course, this way Docker won't cache all you wanted, but better to have something cached than nothing.
Okay,
so to solve this problem, i used docker volumes:
docker run --rm -v <my-java-app>:/app -v <a folder to maven repository>:/root/.m2 -w /app maven:3.6-jdk-8 mvn clean install -T 2C -DskipTests=true
This is the best solution we will get presently.
Related
I am having difficulty in getting this ojdbc7 JAR file installed in the correct location. I tried the following from Windows 10 command prompt and got the BUILD SUCCESS message as shown below:
C:\Users\john>mvn install:install-file -Dfile=C:\ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # standalone-pom ---
[INFO] Installing C:\ojdbc7.jar to C:\Users\l-john\.m2\repository\com\oracle\ojdbc7\12.1.0.1\ojdbc7-12.1.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.381 s
[INFO] Finished at: 2018-10-24T12:09:04-05:00
[INFO] ------------------------------------------------------------------------
However, when I went inside the 12.1.0.1 folder (located here C:\Users\john\.m2\repository\com\oracle\ojdbc7\12.1.0.1) I only saw the following files :
For one of my Maven project, eclipse(version 2018-19) is trying to access the JAR file and I keep getting following BUILD FAILURE message which is obvious since the file isn't there:
BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.208 s
[INFO] Finished at: 2018-10-24T12:15:39-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.company.ii:MyProject:war:0.1: Could not find artifact com.oracle.jdbc:ojdbc7:jar:12.1.0.1 in spring-releases (https://repo.spring.io/libs-release) -> [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.
In my pom.xml, I do have the dependency defined as follows:
Is there anything I am doing wrong? Please let me know if I need to perform some additional testing?
I could see that in mvn install command -DgroupId is not correct, instead of giving "-DgroupId=com.oracle.jdbc", you have given just "-DgroupId=com.oracle"
Maven tells you it is installing the jar to
C:\Users\l-john\.m2\repository\com\oracle\ojdbc7\12.1.0.1\ojdbc7-12.1.0.1.jar
But you are looking at
C:\Users\john\.m2\repository\com\oracle\ojdbc7\12.1.0.1
l-john vs john
I'm trying to use maven goal of eclipse:to-maven, contained in Apache Maven Eclipse Plugin (RETIRED).
When I executed eclipse:to-maven with -DeclipseDir option, it prints BUILD SUCCESS like the following, but I cannot find the created pom.xml.
C:\Users\sample\Desktop\sample>mvn eclipse:to-maven -DeclipseDir="../jee-oxygen/eclipse"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:to-maven (default-cli) # standalone-pom ---
[INFO] Processing file C:\Users\sample\Desktop\jee-oxygen\eclipse\plugins\ch.qos.logback.classic_1.0.7.v20121108-1250.jar
...
skip the middle part
...
[INFO] Installing C:\Users\sample\Desktop\jee-oxygen\eclipse\plugins\org.eclipse.datatools.help_1.7.0.201701131441.jar to C:\Users\sample\.m2\repository\org\eclipse\datatools\help\1.7.0-201701131441\help-1.7.0-201701131441.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.557 s
[INFO] Finished at: 2017-11-22T06:00:23+09:00
[INFO] Final Memory: 16M/621M
[INFO] ------------------------------------------------------------------------
I'm using
Windows 10 Pro
Maven 3.5.0
1.8.0_131
Eclipse Oxygen.1 Release (4.7.1)
And I tried it with other version, like maven 3.3.9 and eclipse Juno, but this did not solve my problem.
edited.
I thought eclipse:to-maven goal is for my eclipse project, so I expected the created pom.xml is for my eclipse project.
I know converting to maven project in eclipse UI, but I would like to know if there are plugins or goals that enable to convert eclipse projects to maven projects.
From eclipse:to-maven plugin documentation
Add eclipse artifacts from an eclipse installation to the local repo. This mojo automatically analize the eclipse directory, copy plugins jars to the local maven repo, and generates appropriate poms.
So you should search in your local maven repo.
For example pom generated for org.eclipse.datatools.help should be installed at C:\Users\hyojinbae\.m2\repository\org\eclipse\datatools\help\1.7.0-201701131441\help-1.7.0-201701131441.pom
I'm working on a project which has 4 modules each in its own git repo and with its own release cycle:
parent-pom
lib1
lib2
server1
There is also another project, say "server2" which also depends on lib1 and lib2 and inherits the parent pom.
I have them set up in Maven and Teamcity, with release and snapshot artifact repos, but I'm trying to work out how to configure my environment in IntelliJ so that it builds them all together locally on my workstation.
I don't want to do git pushes or mvn deploys every time I change a version in the parent pom or a parameter on the library API.
The parent pom and the libraries are shared by another project, which is why they have separate git repos and release cycles, so that the other project is not constrained by activity on this project.
I want both IntelliJ to pick up, compile and run the latest code changes I make locally, e.g. when running the REST server, and simultaneously I want maven to handle the local changes when I run mvn tasks.
I used the mvn relativePath short-cut in the modules to point to the parent-pom like so:
<relativePath>../shared-parent-pom</relativePath>
I've created an aggregator project for server1 like this in its own directory here:
/workspace/parent-pom
/workspace/lib1
/workspace/lib2
/workspace/server1
/workspace/aggregator-pom
like this:
<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>
<groupId>com.me.stuff</groupId>
<artifactId>aggregator</artifactId>
<packaging>pom</packaging>
<version>1-SNAPSHOT</version>
<modules>
<module>../shared-parent-pom</module>
<module>../gem-utilities</module>
<module>../gem-security</module>
<module>../tardis</module>
</modules>
</project>
This works OK with for test and package, but when I run some plugins, e.g. the dependency plugin:
mvn dependency:tree
I see that Maven is going to the repos to try to download the lib1 snapshot that lib2 is dependent on, and failing:
C:\dev\tools\Java\jdk1.8.0_131\bin\java -Dmaven.multiModuleProjectDirectory=C:\dev\workspace\aggregator -Dmaven.home=C:\IntelliJ-2017.1\plugins\maven\lib\maven3 -Dclassworlds.conf=C:\IntelliJ-2017.1\plugins\maven\lib\maven3\bin\m2.conf -javaagent:C:\IntelliJ-2017.1\lib\idea_rt.jar=62781:C:\IntelliJ-2017.1\bin -Dfile.encoding=UTF-8 -classpath C:\IntelliJ-2017.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2017.1.4 -s C:\Users\adam\.m2\settings.xml dependency:tree
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] lib1
[INFO] lib2
[INFO] server
[INFO] aggregator
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building lib1 1.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # lib1 ---
[INFO] com.me.stuff:lib1:jar:1.0.2-SNAPSHOT
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.0.0-M4:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.0.0-M2:test
[INFO] | \- org.junit.platform:junit-platform-commons:jar:1.0.0-M4:test
[INFO] +- org.lots-of-stuff:lots-of-stuff:jar:1.0.0:test
[INFO] ------------------------------------------------------------------------
[INFO] Building lib2 1.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://my.artifactory.repo:8088/artifactory/snapshot-local/com/me/stuff/lib1/1.0.2-SNAPSHOT/maven-metadata.xml
Downloading: http://my.artifactory.repo:8088/artifactory/snapshot-local/com/me/stuff/lib1/1.0.2-SNAPSHOT/lib1-1.0.2-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] lib1 ............................................... SUCCESS [ 2.612 s]
[INFO] lib2 ............................................... FAILURE [ 2.378 s]
[INFO] server ............................................. SKIPPED
[INFO] aggregator ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.804 s
[INFO] Finished at: 2017-06-30T14:26:32+01:00
[INFO] Final Memory: 29M/275M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project lib2: Could not resolve dependencies for project com.me.stuff:lib2:jar:1.0.2-SNAPSHOT: Could not find artifact com.me.stuff:lib1:jar:1.0.2-SNAPSHOT in local-snapshots (http://my.artifactory.repo:8088/artifactory/snapshot-local) -> [Help 1]
[ERROR]
How do I tell maven not to try to download repos but to act from the locally compiled source code?
Ideally if anyone is doing this in Eclipse, I prefer a solution that works there as well as IntelliJ and on the cmd line.
I know this question has been asked several times.Even i have successfully done this in WINDOWS.But installed ubuntu OS and all set up is done except this.
Here are the following things i did.I Have oracle 11g i downloaded ojdbc6.jar,Installed Maven and run following command
sudo mvn install:install-file -Dfile=/home/nawaz/Downloads/ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install-file (default-cli) # standalone-pom ---
[INFO] pom.xml not found in ojdbc6.jar
[INFO] Installing /home/nawaz/Downloads/ojdbc6.jar to /root/.m2/repository/com/oracle/ojdbc6/11.2.0/ojdbc6-11.2.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.545 s
[INFO] Finished at: 2016-07-15T17:48:32+05:30
[INFO] Final Memory: 8M/208M
[INFO] ------------------------------------------------------------------------
and in .m2 directory
ojdbc6-11.2.0.jar.lastUpdated ojdbc6-11.2.0.pom.lastUpdated I cleaned the mvn -U clean and Update nothing works..Hope someone can find the BUG :)
I faced the same issue. I resolved this issue by checking my maven settings.xml file. My maven local repository is the place where I installed ojdbc6.jar. And when I tried to build my project using eclipse, the maven repository used by eclipse is different. This is causing the problem. I updated maven settings in eclipse and then it's worked fine for me.
To change the maven repo path in eclipse
1.Windows --> preferences
2. Maven --> User Settings
3. And in right side window update the settings
It looks like this:
Finally, I found that some dependency of maven-one-plugin don't install properly. but fix them this plugin work.
question fixed :
I am working on convert a maven 1 project to maven 2 project so I just run this command at the folder of the project:
mvn one:convert
then get a error:
[INFO] Internal error in the plugin manager executing goal
'org.apache.maven.plugins:maven-one-plugin:1.2:convert':
Unable to find the mojo 'org.apache.maven.plugins:maven-one-plugin:1.2:convert' in
the plugin 'org.apache.maven.plugins:maven-one-plugin'
org.apache.maven.model.v3_0_0.PatternSet
Anybody know the reason ? Sorry I just so green on maven and the task is urgent...
Try maven-one-plugin:convert
Please take a look at the plugin manual and check if your configuration matches the required configuration.
http://maven.apache.org/plugins/maven-one-plugin/usage.html
The plugin does exist in central repo
Just wondering if you are running this command using maven 1. If so, can you install maven 2/3 and try?
Edit 1:
Downloaded a sample Maven 1 project from here.
Ran mvn convert:one using the latest maven (maven 3).
Worked successfully
D:\work\sample-echo>mvn one:convert
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-one-plugin:1.2:convert (default-cli) # standalone-pom ---
[INFO] Adding report org.apache.maven.plugins:maven-changes-plugin
[INFO] There are 14 plugin relocators available
[INFO] Writing new pom to: D:\work\sample-echo\pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.950s
[INFO] Finished at: Wed Jun 22 15:01:52 IST 2011
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------