I have a multi-module project with a common parent pom to all modules and an aggregator/build pom. I am trying to use the maven-versions-plugin to update/set the versions of all my modules, but it keeps skipping the child modules.
Project layout:
- common/pom.xml (build pom)
- common/superpom/pom.xml (parent pom)
- module1/pom.xml (module1 pom)
- module2/pom.xml (module2 pom)
common/pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.bic</groupId>
<artifactId>builder</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Builder</name>
<modules>
<module>../module1</module>
<!-- POM Component Versionning -->
<module>../module2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
</project>
I have tried adding the plugin to the build pom (common/pom.xml) and then calling:
mvn versions:set -DnewVersion=999999
Maven lists all the props it found in the child modules, so I know it is parsing them all properly:
Props: {project.version=50, project.parent.version=1.0-SNAPSHOT, project.parent.groupId=com.bic, project.artifactId=module1, project.groupId=com.bic, project.parent.artifactId=common}
Props: {project.version=50, project.parent.version=1.0-SNAPSHOT, project.parent.groupId=com.bic, project.artifactId=module2, project.groupId=com.bic, project.parent.artifactId=common}
but it doesn't actually update the versions of any of the module poms, which is what I am looking to do.
[INFO] Reactor Summary:
[INFO]
[INFO] Module1 ........................................ SKIPPED
[INFO] Module2 ........................................ SKIPPED
[INFO] Builder ........................................ SUCCESS [ 2.037 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.975 s
[INFO] Finished at: 2015-01-26T11:48:11-05:00
[INFO] Final Memory: 24M/44M
[INFO] ------------------------------------------------------------------------
And the update-child-modules goal doesn't allow me to explictly set a version number for the child modules.
Am I using the plugin incorrectly?
Couldn't figure out how to do it using the versions-maven-plugin directly, so I ended up doing it manually.
find . -name "pom.xml" -exec mvn versions:set -DnewVersion=1.0.3-SNAPSHOT -f {} \;
This ended up finding all the poms of my child modules and updating the version number in each. Definitely slower than using the plugin on the parent as it was designed to be done, but functional.
A solution was introduced in version 2.5 of plugin versions-maven-plugin
mvn versions:set -DnewVersion=1.6-SNAPSHOT -DprocessAllModules=true
or if like me you need to force the version:
mvn org.codehaus.mojo:versions-maven-plugin:2.5:set -DnewVersion=1.6-SNAPSHOT -DprocessAllModules=true
This is a little late to the party, but I just found the answer. You need to run the versions:set goal on the parent project directly. It will take care to scan for an aggregator POM nearby (probably only looks up one directory, but I am not positive), and will update the parent, aggregator, and all child modules just as you expect.
The root POM is the aggregator and lists parent, module1, and module2 as modules:
DANIJOH2-M-V0MA:test danijoh2$ ls
module1 module2 parent pom.xml
The root aggregator POM, module1, and module2 all refer to parent/pom.xml as their parent POM. Move into the parent and run the versions:set goal:
DANIJOH2-M-V0MA:test danijoh2$ cd parent
DANIJOH2-M-V0MA:parent danijoh2$ ls
pom.xml
DANIJOH2-M-V0MA:parent danijoh2$ mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=1.0.0 -DgenerateBackupPoms=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.1:set (default-cli) # parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /Users/danijoh2/Desktop/test
[INFO] Processing com.cisco.dan.test:parent
[INFO] Updating project com.cisco.dan.test:parent
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.cisco.dan.test:aggregator
[INFO] Updating parent com.cisco.dan.test:parent
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] Updating project com.cisco.dan.test:aggregator
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.cisco.dan.test:module1
[INFO] Updating parent com.cisco.dan.test:parent
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] Updating project com.cisco.dan.test:module1
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO]
[INFO] Processing com.cisco.dan.test:module2
[INFO] Updating parent com.cisco.dan.test:parent
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
[INFO] Updating project com.cisco.dan.test:module2
[INFO] from version 1.0.0-SNAPSHOT to 1.0.0
Related
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 have a Maven multi-module project in Eclipse.
Each time I want to update the version, I go to Run As -> Run Configurations..., change the parameter newVersion of the goal versions:set to a higher number and then run the goal.
Is there something more direct?
Note that I cannot use the CI-friendly versions because they clash with the Maven release plugin.
Following the idea of https://stackoverflow.com/a/34091470/927493,
I configured the newVersion parameter to be ${string_prompt:newVersion} as shown in the image below
Then I get prompted for the version number which works fine.
Based on the answer from JF Meijer, here's a Launch Configuration explanation for M2E, which I suspect you already have installed, which does exactly what you're asking.
Launch Create Dialog
Open "Run Configurations..."
Select "Maven Build"
Click "New Launch Configuration" (in the top left)
Give it a name (Like "Set Version")
Click "Workspace..." And select the parent pom project
Enter "versions:set" under Goals
scroll down (can be hidden)
Under "Parameters" select Add... on the right
Add a Parameter with
Name = newVersion
Value = ${string_prompt:"New Version":0.0.1-SNAPSHOT}
so, to expand on what JP Meijer already pointed out, the variable string_prompt, as shown under step 9, supports a distinct name, like "New Version", and a default value, in this case 0.0.1-SNAPSHOT.
Now, Apply, Save, and Run!
Here is a script that checks if the maven build system needs updates. By running this script, you will get all the updates (but none of them will be applied). This lets you change all, some or none, as you see fit.
mvn versions:display-plugin-updates
mvn versions:display-parent-updates
mvn versions:display-dependency-updates
I typically save this script in a top-level check-versions.sh or check-versions.cmd (adjusting for the scripting language).
For this script to work, in /project/build/plugins you'll need the org.codehaus.mojo:versions-maven-plugin:2.7 or greater. I typically configure the plugin like so
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
As this doesn't make backup pom.xml files which pollute my git history.
The first few times you run this, you might notice that the inherited plugins show themselves to be out of date (as they are effectively built-in to the defaults in the maven default parent pom.xml). You will have to explicitly define the defaults to a newer release to get them to stop reporting.
In addition, you will find that a lot of the plugins will still report because it isn't clear what is the minimum required version of Java and the minimum required version of Apache Maven. To encode these requirements into the pom.xml, you will use the Maven Enforcer plugin. An example of mine that forces Maven version 3.5.4 and Java version 11 is
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.5.4</version>
</requireMavenVersion>
<requireJavaVersion>
<version>11</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
With these tools in place, I currently get the output on one of my projects
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-plugin-updates (default-cli) # pascal-adapter ---
[INFO] artifact com.github.sevntu-checkstyle:dsm-maven-plugin: checking for updates from central
[INFO] artifact net.nicoulaj.maven.plugins:checksum-maven-plugin: checking for updates from central
[INFO]
[INFO] The following plugin updates are available:
[INFO] maven-project-info-reports-plugin .................... 2.6 -> 3.0.0
[INFO]
[INFO] All plugins have a version specified.
[INFO]
[INFO] Project inherits minimum Maven version as: 3.5.4
[INFO] Plugins require minimum Maven version of: 3.2.1
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.976 s
[INFO] Finished at: 2020-04-16T07:52:12-05:00
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-parent-updates (default-cli) # pascal-adapter ---
[INFO] Project does not have a parent.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.325 s
[INFO] Finished at: 2020-04-16T07:52:15-05:00
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.edwbuck.parserhelp:pascal-adapter >----------------
[INFO] Building pascal-adapter 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:display-dependency-updates (default-cli) # pascal-adapter ---
[INFO] artifact com.edwbuck.parserhelp:pascal_client: checking for updates from central
[INFO] artifact org.junit.jupiter:junit-jupiter-engine: checking for updates from central
[INFO] artifact org.junit.jupiter:junit-jupiter-api: checking for updates from central
[INFO] artifact org.influxdb:influxdb-java: checking for updates from central
[INFO] The following dependencies in Dependencies have newer versions:
[INFO] org.junit.jupiter:junit-jupiter-api ................... 5.6.0 -> 5.6.2
[INFO] org.junit.jupiter:junit-jupiter-engine ................ 5.6.0 -> 5.6.2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.848 s
[INFO] Finished at: 2020-04-16T07:52:18-05:00
[INFO] ------------------------------------------------------------------------
which indicates I need to update my maven-project-info-reports-plugin and my org.junit.jupiter:junit-jupiter-api and org.junit.jupiter:junit-jupiter-engine plugins.
Normally I don't use the maven versions plugin to actually do the update in the pom.xml file, because text editors are fast, if you're doing all the updates you want to do in the pom.xml at one time.
Currently the maven versions plugin offered by codehaus doesn't have an command line option to automatically update more than one version at a time. The reasons it is not there is simple. To use the versions:update-properties plugin, one needs to either:
Define the update policy (what to update / what not to update) in the pom.xml.
Define the update policy (what to update / what not to update) on the command line.
These policies are verbose as they cover the entire project. Yes, they can use glob matching, but they're still verbose. For my personal projects, I notice that for them to give me proper handling, I update them too often, so I leave them out of the picture, instead deciding what to update or not update at the time I work on the output of my check-updates script.
That's because it is not always safe to automatically update plugins and dependencies. Sometimes the next version of a plugin requires code changes to the project. For example, projects shifting from Java 8 to Java 9 require alterations to how they are built and linked. The same goes for dependencies, if you want to keep the code bound to non-deprecated APIs.
I got a multi-module project. Each project has its own unittest same for the parent project. When I use mvn test no tests are run and the target folder does not contain any test classes. Parent project doesn't even create a target folder
Structure looks like this:
|-module1-> pom.xml
|-module2-> pom.xml
|-module3-> pom.xml
|-src/main
|-src/test/java/MyTest.java
|-pom.xml
See poms below ( I omited standard pom boilerplate)
parent pom.xml
<groupId>com.tests</groupId>
<artifactId>unit-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>RELEASE</version>
</dependency>
<dependencies>
Child pom has:
<parent>
<groupId>com.tests</groupId>
<artifactId>unit-tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Whenever i run mvn clean test no tests are run and in the console i get something like:
[INFO] ------------------------------------------------------------------------
[INFO] Building unit-tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
Btw, parent project does not have any source code, just tests
You're using packaging pom. With that kind of packaging you're only allowed to run a small number of goals bound to phases (like install and deploy). In order to run the tests in the parent you must be explicit about your intentions, like this:
$mvn clean compiler:testCompile surefire:test
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.tests.unit_tests.TestModules
Test1!
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.016 s <<< FAILURE! - in com.tests.unit_tests.TestModules
[ERROR] test1(com.tests.unit_tests.TestModules) Time elapsed: 0.003 s <<< FAILURE!
java.lang.AssertionError
at com.tests.unit_tests.TestModules.test1(TestModules.java:11)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] TestModules.test1:11
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] unit-tests ......................................... FAILURE [ 1.262 s]
[INFO] module1 ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.473 s
[INFO] Finished at: 2017-12-02T11:04:50-02:00
[INFO] Final Memory: 16M/207M
[INFO] ------------------------------------------------------------------------
That way you are telling maven that you want to compile (generate your target) and run your tests in the aggregator (which has the parent pom). Otherwise maven will only run the tests in the modules.
$mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] unit-tests
[INFO] module1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building unit-tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module1 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # module1 ---
[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.2:compile (default-compile) # module1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # module1 ---
[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.2:testCompile (default-testCompile) # module1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # module1 ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] unit-tests ......................................... SUCCESS [ 0.002 s]
[INFO] module1 ............................................ SUCCESS [ 0.424 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.504 s
[INFO] Finished at: 2017-12-02T11:06:24-02:00
[INFO] Final Memory: 9M/241M
[INFO] ------------------------------------------------------------------------
I know that it is a hard reading, but you should check it out:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Packaging
For example, a project that is purely metadata (packaging value is
pom) only binds goals to the install and deploy phases (for a complete
list of goal-to-build-phase bindings of some of the packaging types,
refer to the Lifecycle Reference).
EDIT
As eis pointed out. Even though it's possible to do it, maven made it hard to do it because you SHOULDN't do it by default. Your unit tests should be in the module they are testing. It's not a good practice to scatter them.
The answer is: you can do it, yes. But you shouldn't! There are somethings in life that you can do, but shouldn't...
If we were talking about integration tests that would be a different story.. That's a different discussion.
Cheers!
The maven surefire plugin runs all JUnit Test where the name of the testclass ends with Test - with a capital 'T'. According to your info your test class is named Mytest. Refactor that class to be named MyTest will make it work.
multimodule parent has the packaging pom, and as such, can by definition only contain the pom, not any source code (not even test source code!). This is the reason your tests won't run and you don't get a target folder: there cannot be anything to run or compile on a project of type pom. A multimodule parent is only meant to group the modules together.
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 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