How to use pom.xml file with a simple Java project - java

I have created a simple Java project in Eclipse and created a pom.xml file in the root folder. Now I want to download all of the Spring Framework dependencies by executing the pom.xml file.
Is it possible to use the pom.xml file in a simple Java project not in a Maven project and download all of the Spring Framework dependencies?
I have right clicked on pom.xml file and run as "Maven install"
on console i found this.
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # my-app ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # my-app ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # my-app ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # my-app ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/target/my-app-1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # my-app ---
[INFO] Installing /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/target/my-app-1.jar to /home/oodles/.m2/repository/com/qasim/app/my-app/1/my-app-1.jar
[INFO] Installing /home/oodles/Documents/MyWorkspace/MySpringProjectMaven/pom.xml to /home/oodles/.m2/repository/com/qasim/app/my-app/1/my-app-1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.013 s
[INFO] Finished at: 2015-03-18T23:32:49+05:30
[INFO] Final Memory: 8M/150M
[INFO] ------------------------------------------------------------------------
i could not understand what happen after clicking on Maven install. Some folder created named target folder with my-app.jar and i added this jar to build path . But i think it is not working. I have Test class with following code:
package com.qasim.app;
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("MySpringConfig.xml");
Restaurant obj = (Restaurant) context.getBean("restaurantBean");
obj.greetCustomer();
}
}
And pom.xml file:
<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.qasim.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
</dependencies>
</project>
But in Test class compiler complaing at application context line "create class named applicationContext" if the dependencies got downloaded after running "Maven install" command then it should show some "Import hint" for application context

Update:
A advice to start off: I realy recomend to consult the official documentation found here http://maven.apache.org/guides/index.html - take your time to read at least the points below "Introductions" since it will explain you on how to use Maven and how it works ;)
I copy&pasted your pom.xml and could compile your Java class (well i removed the Restaurant reference and just created a empty file for the Spring config).
Looking at your build output:
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # my-app ---
[INFO] No sources to compile
Maven tells you it dit not compile any sources - this strongly implies you are not using the correct standard Maven folder structure.
I just set up a mini-project using your pom.xml and the Maven standard folder structure like so:
(Note: I had to remove the paths due to company security restrictions as I am writing from within my office)
If you setup your classes under src/main/java and place your config under src/main/resources Maven will be able to locate the class and compiles it while it will also take your resources and places them in your jar. In my case i just created a empty file MySpringConfig.xml which obviously wont work when trying to load the ApplicationContext you can however see in the stacktrace below that the file itself could be found and loaded (but while parsing it the empty content was not satisfying for the SAX-parser - i bet yours looks better :).
Try it out and dont forget to consult the maven reference since i did not go too deep into the folder structures etc. ;)
Yes - you should be able to right click the pom.xml, choose run AS and for example choose Maven install (corresponds to mvn install) or define the phases to be processed under Maven build...
Alternatively you should be able to create a new Launch configuration for Maven and point the Base directory: to where your pom.xml resides.
Note: Afaik you need the M2-Plugin installed in Eclipse to work with Maven (i dont know lots about that funny tool but i have a Eclipse Juno here that was able to build a Maven project created manually inside a "simple java application" project).
Note: If you just need the dependencies and use Maven as a "helper" to download them you can always manually download the Jar from most remote repositories like for example here: http://mvnrepository.com/search?q=spring

Related

Maven tries download multimodule dependency on `validate` phase

From a build pipeline I want to run validate phase for things like the enforcer plugin. However it does not work for a multimodule project as it tries to download dependencies from repository which are inside the project. However, compile phase does not do that, but for me it is not an option as it is too slow.
pom.xml:
<module>lib</module>
<module>app</module>
lib/pom.xml
<version>1.2.3</version>
app/pom.xml
<dependency>
<artifactId>lib</artifactId>
<version>1.2.3</version>
</dependency>
So, if I do mvn compile it works fine.
But if I do mvn validate it fails validating app module as it tries to download lib-1.2.3 from maven repo. For some reason it now could not see that the lib is a neighbour dependency. Why?
I have created a small repo: https://github.com/kan-izh/so63963768
mvn compile
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-no-snapshots) # app ---
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # app ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Workspace\repo\so63963768\app\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # app ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................ SUCCESS [1.612s]
[INFO] lib ............................................... SUCCESS [1.224s]
[INFO] app ............................................... SUCCESS [0.056s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
mvn validate
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (enforce-no-snapshots) # app ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................ SUCCESS [0.979s]
[INFO] lib ............................................... SUCCESS [0.015s]
[INFO] app ............................................... FAILURE [0.020s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.180s
[INFO] Finished at: Wed Sep 23 11:27:38 BST 2020
[INFO] Final Memory: 7M/34M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce (enforce-no-snapshots) on project app: Execution
enforce-no-snapshots of goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce failed: org.apache.maven.shared.dependency.graph.
DependencyGraphBuilderException: Could not resolve following dependencies: [com.so.q63963768:lib:jar:1.2.3 (compile)]: Could not resolve depend
encies for project com.so.q63963768:app:jar:1.2.3: Failure to find com.so.q63963768:lib:jar:1.2.3 in http://xxxxxxxxxxxxx.xx.xxxxxxxxxxxxxxxxx.
com:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has
elapsed or updates are forced -> [Help 1]
This is a good question, and it shows a small flaw in how Maven handles dependencies.
You need to know that for every plugin-goal you can define if dependencies should be resolved, and for which scope. (and there's a small difference if having only the poms is enough, or that you also need the artifacts)
compiler:compile requires the dependencies that are required during compile, compiler:testCompile requires the dependencies that are required during test.
For the enforce goal it is tricky: the goal itself doesn't require to have resolved dependencies, nor do most rules( like requireJavaVersion or requireMavenVersion), but some rules do, like the one you try to enforce.
Ideally rules can define if they need to have resolved dependencies, but right now the API doesn't support that.
So you have a couple of solutions: always run with compile, or have an execution-block bound to the compile-pahse if it requires artifacts.

I am new to Selenium, but why is Maven skipping over my test and telling me the build was successful?

I been trying for the past 3 hours to try to get a single MyTest.java file to run. But no matter what I try, Maven seems to want to skip over my test and tell me BUILD SUCCESS. But I wasn't try to build anything. I was just trying to "Maven Test".
When I run MyTest.java by itself, it runs fine , but for some reason Maven wants to skip over it.
This is what I wrote.
package SeleniumT;
import org.testng.annotations.Test;
public class MyTest {
#Test
public void login() {
//return "sample";
System.out.println("########This is my first Maven project#######");
}
}
My console output keeps saying there is nothing to compile, which makes no sense.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # maven-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # maven-demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # maven-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # maven-demo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.287 s
[INFO] Finished at: 2018-02-15T17:27:11-05:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------
My POM file has all the dependencies required to run this. I don't have Maven Surefire plugin I think, but that shouldn't cause a issue, I am assuming.
<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>SeleniumT</groupId>
<artifactId>maven-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.43.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
What could be causing Maven to skip my simple Java test?
First of all, I noticed your java file is called apptest.java but your actual public class definition is named MyTest. Rename the java file to MyTest.java. Such a difference usually raises compilations error, what makes me believe you Eclipse project is not set to Build automatically.
If that's not the problem, maybe the Maven Test option you have invoked is not invoking test goal. Concerning the "Nothing to compile" message, I'd suggest you to always perform a clean so maven get rid of previously compiled classes and build it from scratch again.
Summing up: right click on the project > Run As > Maven Build... > Type clean test on the Goals field > Click Run. Check if something has changed.
If you succed, the next time you need to run this again, this run configuration you've just created will be already listed on the Run As > Maven build menu.

Oracle ojdbc8 12.2.0.1 Forbidden by Maven

Oracle ojdbc8 12.2.0.1 Forbidden by Maven since December 2017, before that worked well. What configuration has changed on the Oracle repository (setting.xml)?
Maven project: https://github.com/sgrillon14/MavenSampleOracleJdbc
Full trace: https://travis-ci.org/sgrillon14/MavenSampleOracleJdbc
This is from the Maven Central Repository. Please try with these maven settings in your pom file to pull from the Maven Repository. The Group Id is different.
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
Since Oracle JDBC Driver is not in Maven repository, Download ojdbc8.jar and run the below command.
mvn install:install-file -Dfile=/home/cm/Videos/ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.1.0.2 -Dpackaging=jar
Add this dependency in pom.xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.1.0.2</version>
</dependency>
It's possible that the Oracle Maven terms have changed. You may need to re-register on the Oracle Maven site: http://www.oracle.com/webapps/maven/register/license.html
I tried your github script and it worked fine with me:
$ mvn clean install --settings test/mvnsettings.xml
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mavensampleoraclejdbc 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # mavensampleoraclejdbc ---
[INFO] Deleting /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # mavensampleoraclejdbc ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # mavensampleoraclejdbc ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # mavensampleoraclejdbc ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # mavensampleoraclejdbc ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # mavensampleoraclejdbc ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # mavensampleoraclejdbc ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/target/mavensampleoraclejdbc-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # mavensampleoraclejdbc ---
[INFO] Installing /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/target/mavensampleoraclejdbc-1.0.0-SNAPSHOT.jar to /Users/jean/.m2/repository/com/github/sgrillon14/mavensampleoraclejdbc/1.0.0-SNAPSHOT/mavensampleoraclejdbc-1.0.0-SNAPSHOT.jar
[INFO] Installing /Users/jean/Downloads/MavenOracle/MavenSampleOracleJdbc-master/pom.xml to /Users/jean/.m2/repository/com/github/sgrillon14/mavensampleoraclejdbc/1.0.0-SNAPSHOT/mavensampleoraclejdbc-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.900 s
[INFO] Finished at: 2018-02-12T17:06:49+01:00
[INFO] Final Memory: 12M/309M
[INFO] ------------------------------------------------------------------------
wagram:MavenSampleOracleJdbc-master jean$
Here's the underlying problem
Access denied to: https://maven.oracle.com/com/oracle/jdbc/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom , ReasonPhrase:Forbidden
I'm guessing you have the wrong username/password in your settings.xml. Try hitting the URL in your browser and enter the username/password. Possibly your credentials have expired? Or maybe you have a different settings.xml on travis than your localhost?
If you don't have dependency add it otherwise for oracle, replace it with the following code:
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
I tested for downloading ojdbc8.jar from 12.2.0.1. I was able to download without any issues. But, there is a warning. But, the warning is due to the missing *.md5 file in the maven repository. (We are looking into that issue)
Downloading: https://maven.oracle.com/com/oracle/jdbc/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom
[WARNING] Checksum validation failed, expected 3626be7f20ea523d9fd6aca576d5aba3f7afb3fe but is f1be766b419370110b86bd088a69c1bfcdca6989 for https://maven.oracle.com/com/oracle/jdbc/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom
Downloaded: https://maven.oracle.com/com/oracle/jdbc/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom (7 KB at 0.4 KB/sec)
The Oracle Maven repository requires you to agree with the terms and conditions of using it. Thus, in order to provide this agreement:
go to Oracle.com and login
go to https://maven.oracle.com
the page shown shows:
...
Directory browsing is not allowed on the Oracle Maven Repository.
Registration is required to access the Oracle Maven Repository. To register, please visit the registration site.
...
The link to the "registration site" is actually http://www.oracle.com/webapps/maven/register/license.html
where you have to accept the terms and conditions. This allows you to use the Oracle Maven repository.
For further details on setting up Maven and published drivers, pleaase refer to
https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides
version in the MANIFEST is 12.2.0.1.0 not 12.2.0.1 but still the problem
"Content Server Request Failed
Error Unable to download '(null)'. 'path:/Enterprise Libraries/content/maven/content/com/oracle/jdbc/ojdbc8/12.2.0.1/ojd‌​bc8-12.2.0.1.pom' does not exist.
"
my credential are OK and got the problem on
https://www.oracle.com/content/secure/maven/content/com/oracle/jdbc/ojdbc6/ojdbc6-11.2.0.4.0.pom
(the URL you are redirected to when accessing to maven.oracle.com)
too
FYI:
Latest attempt this Sat 6/01/2018 morning: OK, was able to download ojdbc8 POM from a browser.
This artifact was moved to:
com.oracle.database.jdbc » ojdbc10

Where is the created pom.xml

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

Coding multiple modules from multiple git repos with different release cycles in IntelliJ / Maven

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.

Categories