I have this file structure in my project:
Project
|--pom.xml
|--Sub-Module1
|----pom.xml
|--Sub-Module2
|----pom.xml
|--Sub-Module3
|----pom.xml
I want to create a JAR-file from Sub-Module2 (SM from now on). However, that module depends on SM1 and SM3. What I want to do is simply run "mvn package" from SM2 and it would run "mvn install" for SM1 and SM3. I already have SM1 and SM3 added to SM2's pom.xml as dependencies, so they get packaged in the JAR-file, but each time I start from fresh, I have to separately run "mvn install" in SM1 and SM3.
Is there a plugin for that or can I install other modules from SM2 in other means?
Invoke mvn package on project level insteed of module level. This way Maven will build all three modules, and include required dependencies in generated jar as expected.
I assume that pom.xml in Project directory, is a parent pom for submodules.
EDIT: After quick check on Maven docs, you could use mvn --also-make and this should build dependant modules as well.
Related
I have 2 Java projects where project2 depends on project1's jar. Bot are Maven projects. At the moment this is what I do to create a jar from project2:
c:\eclipse\workspace\project1> mvn install
c:\eclipse\workspace\project2> mvn package
Could I somehow "include" the mvn install command inside projects2's pom.xml so that only the last command would be enough to create the jar?
You have described a basic use case of Maven Reactor (i.e. Maven's fancy name for multi-project/module build).
In this respect, you'd have your two projects alongside a parent pom (which would be the predecessor of both project1 and project2).
Within a Maven multi-module build, modules are allowed to depend one on another; so in your case you'd specify project1 as a dependency of project2's just like you do with any other dependency. Then, when you run package (on the parent pom) Maven will see the dependency, build project1 first and then use the built jar for project2.
I want to deploy this https://github.com/OhadR/oAuth2-sample
as how to author says.
How do I get the 3 war files?
Which maven goal should I run from command line?
oAuth2-sample is the parent module.
The role of this module is to build the other modules defined within pom.xml
So if you see there are 3 modules defined in it(though 2 are commented out),
<modules>
<!--module>auth-common</module>
<module>common-crypto</module-->
<module>authentication-flows</module>
</modules>
So if you run the maven, it will build all the modules as either by jar,war as defined in their individual pom.xml file.
Maven command that you can use,
maven clean - To clear the class files of the projects
maven compile - To compile the source code of the projects
maven install - To install the project in m2 repository for use as dependency for other modules.
I have a multi modules Maven project : a parent and three child modules.
I want all of the modules to be built when I run mvn clean package on the parent. But I would also like one of those module to not be uploaded to Nexus when using mvn deploy (or mvn release:prepare and mvn release:perform) on the parent. I want this module to be skipped, ignored. Only the parent and the two other modules would be uploaded to Nexus.
Is there a way to achieve that?
The maven deploy plugin has a skip property: http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html
That should do what you want. The user property is "maven.deploy.skip".
There's a Maven project I want to use as a dependency for one of my projects. I downloaded the project and ran "mvn install", which installed it to my /.m2/repository/ folder. I added the dependency in my POM file. When working in my IDE (IntelliJ IDEA), I can use the dependencies correctly and run my program. Whenever I do a mvn package or mvn install from the command line (for my program), however, I get:
Failed to execute goal on project MyProject: Could not resolve
dependencies for project...
And then it lists each dependency that I specified in my POM.
If I run mvn with -X, I see that it's pointing to the right settings.xml file and .m2 folder for my local repository. Does anyone know why it sees the artifacts correctly when I work in my IDE, but not from the command line?
I have a project which has dependency A.
Project is packing into WAR and dependency A - into jar.
And another dependency B, which also depends on A.
I want to pack project and when project B is packing it must rebuild its dependency A instead of getting compiled dependency.
Please help, how can i achieve this
Always perform a clean when doing an install, ie mvn clean install. This will make sure that all modules in the project are rebuilt, packaged, and installed in the local .m2 repository for inclusion by parent dependencies and projects.
What you may want is a multi-module project containing your three projects (WAR, A and B). Then you can run mvn package on the multi-module project and it will build and package all of the latest project code against each other without having to run mvn install to update the dependencies in your local repository first.