I have the following maven-setup:
parent-project
|- libraries
|- utilities
|- core
|- component1
|- component2
in the parent i define all dependency- and pluginmanagement and the infos about the dev-team. utilities containing functional artifacts like the website skin and checkstyle-config, libraries are bundle-artifacts for simplifying the dependencies. The site is build on the core-module and its sub modules. The parent-part of the core pom.
<parent>
<artifactId>parent</artifactId>
<groupId>my.group</groupId>
<version>3.0.0</version>
</parent>
<artifactId>core</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
When staging or deploying the site, the page is located in a "core"-subdir (e.g. /target/staging/core/index.html). Is there a way to locate the site of core in the root?
Atm i use a "dirty hack". On the webserver i created a syslink with ln -s ./ core so he don't knows its the same dir.
Solution was, that maven generates that subdirectory only, when the url for deploying is inherited from the parent. All I need to do was move the distributionManagement section for site deploy and the url element from parent to core.
Related
We have a Spring Boot app (exposing REST services) with multiple modules and for dev purposes we're using the default Spring Boot build approach - Maven builds it as one executable war file, that has Tomcat embedded into it.
For productive deployment purposes this doesn't work. We already have web app servers setup and we need a regular, non-executable war, that can be deployed on those servers. I already figured out, how I can build it.
We also will have another, related web apps (war files) deployed on the same productive servers (e.g. - simulator of the app). Of course, they will use (some of) the same modules, so the question it raises is how to setup maven to build the war and the module jars outside of it, so the other apps (war files deployed on the same server) could have dependencies on them. I couldn't find a good explanation/example how to do that.
Any ideas, links, blogs?
This is really more of a Maven question than Spring Boot. When you have a multi-module project Maven still creates individual artifacts for each module so you can still reference them as dependencies elsewhere.
For example in my setup with Spring boot I have the parent project and the modules underneath it. Most of the modules are jar artifacts, some with dependencies on other modules in the project and of course some external dependencies as well. By using the parent we can standardize some of the versions used in the dependencies using placeholders in the parent. Since the artifacts are still built and published separately you can reference them in other projects, which is what I believe you are asking.
For example (just the main tags and not all of them):
Parent:
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<packaging>pom</packaging>
<version>1.1.2-SNAPSHOT</version>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
Module1:
<parent>
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
</parent>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>
Module2:
<parent>
<groupId>com.somecompany</groupId>
<artifactId>project-parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
</parent>
<groupId>com.somecompany.apps</groupId>
<artifactId>project-webapp</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>war</packaging>
<!-- dependency on other module -->
<dependency>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>${project.version}</version>
</dependency>
Some Other Project:
<groupId>com.somecompany.apps</groupId>
<artifactId>project-webapp-services</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- dependency on other module which is published -->
<dependency>
<groupId>com.somecompany.tools</groupId>
<artifactId>project-tools-core</artifactId>
<version>1.1.1</version>
</dependency>
So in this case assuming you had published version 1.1.1 of your parent and its modules you can have another project refer to any of those published artifacts. Maybe it is the release and publishing step you are missing.
I want to migrate about 15 Ant projects to Maven.
Current build with Ant:
project-1
project-2 (needs project-3 as dependency)
project-3
project-webresources (contains web resources needed by ALL other projects)
project-WAR (empty target project)
(project-1, project-2, project-3 contain additional web resources)
Now, different WARs have to be built:
For Deployment 1 (contains project-1 and project-webresources):
Java sources from project-1 are compiled and copied to project-WAR/WEB-INF/classes
Web resources from project-webresources and project-1 are copied to project-WAR/
For Deployment 2 (contains project-1, project-2, project-3 and project-webresources):
Java sources from project-1, project-2, project-3 are compiled an copied to project-WAR/WEB-INF/classes
Web resources from project-webresources, project-1, project-2 and project-3 are copied to project-WAR/
My plan to realize it with Maven:
The projects become modules and for every deployment I create a project which holds the needed modules and one target WAR artifact. For the project-webresources I use maven overlays.
Build-deployment-1:
(mvn install here to build the deployment-1 Web archive)
<packaging>pom</packaging>
<modules>
<module>project-1</module>
<module>project-webresources</module>
<module>WAR-deployment-1</module>
</modules>
WAR-deployment-1:
<packaging>jar</packaging>
<dependency>
<groupId>com.groupId</groupId>
<artifactId>project-webresources</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.groupId</groupId>
<artifactId>artifact-1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
For the second WAR there will be projects like Build-deployment-2 and WAR-deployment-2 and so on which use other module combinations.
My problem:
What is the best way to copy all web resources from project-1 to WAR-deployment-1? If I use maven-resources-plugin in project-1 to copy resources to WAR-deployment-1 the target directory is hard coded to WAR-deployment-1. What if project-1 is part of build-deployment-2 and files have to be copied to WAR-deployment-2?! Can I use build properties for this? Or is the assembly plugin a solution?
So I have a file structure that looks like this:
.git
.project
.classpath
app1
pom.xml
.classpath
.project
src
app2
pom.xml
.classpath
.project
src
app3
pom.xml
.classpath
.project
src
TheAppIWorkOn
pom.xml
.classpath
.project
src
TheAppIWorkOn uses jars from app1, 2, and 3 which are maven dependencies so when I need to edit something in app1, 2, or 3 it's a painful process. If I use the "jump to declaration" functionality it just shows me the locked jar. Is it possible to set it up so that when I "Jump to declaration" it take me to the actual code that I can make edits on?
If you would have a maven reactor build it would have made all the module setup for you. Now you only have dependencies to jar files and IntelliJ cannot know that you have the modules to depend on. But you can help IntelliJ by pointing out the module dependencies and after that you will be able to navigate between all the classes in the project.
The best way would be to create a pom.xml in the root directory of the project. This pom would keep together the different modules and also define the build order. When you want to open the project for the first time you just point IntelliJ to this pom file and all the dependencies would be resolved and setup so the navigation between classes in the different modules is a breeze.
Sample pom file for the root directory:
<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>org.stackoverflow</groupId>
<artifactId>Q16589702</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>app1</module>
<module>app2</module>
<module>app3</module>
<module>TheAppIWorkOn</module>
</modules>
</project>
If you cannot do this for some reason then you'll have to inform IntelliJ about the module dependencies. You do this by opening up the Project Structure.
Then select the module TheAppIWorkOn and press the plus sign in the bottom and choose Module Dependency....
And there you can select all modules that you want to have as dependency.
Press Ok and then Ok again.
Now you will be able to navigate between the different classes in the project.
If app1, app2 and app3 also have dependencies between each other then you will have to do the same for them.
But the simplest way is definitely to have a pom file in the root project directory with all inter module dependencies there.
Consider the following scenario of a flat multi-module layout:
| parent-pom
| - pom.xml
| module1
| - pom.xml
Where parent-pom/pom.xml is the parent POM of all modules:
<groupId>my-group</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0</version>
...
...
<module>../module1</module>
Now, the pom.xml of module1 contains the following parent section:
<parent>
<groupId>my-group</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.0</version>
</parent>
I'm starting with a clean local repository; none of the artifacts is pre-built, everything done from scratch. Trying to execute mvn install on parent-pom will result in an error, because the Maven reactor will look for my-group:base-pom in the local repository, fail (because it's not there) and then look for ../pom.xml.
Fine. My question is this: if the build of module1 is invoked through the build of parent-pom, why does Maven even have to look for the parent's pom.xml anywhere? when Maven comes to build module1, it already knows the following things:
The physical location, of the file system, of my-group:parent-pom:1.0.0.
The fact that module1 is rooted in my-group:parent-pom:1.0.0.
Why look elsewhere?
The Introduction to the POM:Project Inheritance:Example 2 told us as the following: -
The Scenario
However, that would work if the parent project was already installed in our local repository or was in that specific directory structure (parent pom.xml is one directory higher than that of the module's pom.xml).
But what if the parent is not yet installed and if the directory structure is
.
|-- my-module
| `-- pom.xml
`-- parent
`-- pom.xml
The Solution
To address this directory structure (or any other directory structure), we would have to add the <relativePath> element to our parent section.
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-module</artifactId>
</project>
As the name suggests, it's the relative path from the module's pom.xml to the parent's pom.xml.
EDITED:
The getRelativePath told us as the following
Get the relative path of the parent pom.xml file within the check out. The default value is ../pom.xml. Maven looks for the parent pom first in the reactor of currently building projects, then in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent pom. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project.
I hope this may help.
I don't understand what is the parent version and for what it should be good?
We use svn in our team and when I did update for the project the last time I notcied that the parent version is changed:
local pom.xml
<parent>
<artifactId>foo</artifactId>
<groupId>bar</groupId>
<version>0.42-SNAPSHOT</version>
</parent>
svn pom.xml
<parent>
<artifactId>foo</artifactId>
<groupId>bar</groupId>
<version>0.45-SNAPSHOT</version>
</parent>
When does parent version change and for what it should be good?
A parent POM contain settings that apply to all child modules. This may include declaring plugin settings or choosing dependency versions.
A parent POM is no different to any other Maven artifact. It can change and when it does the version number must increment. Typically you want to always be using the latest available version of your parent.
You can use the Maven versions plugin to help manage versions, including forcing an update to the latest available parent version.
Parent pom and child pom come into picture if you have a multi-module project. For example like the below
/myapp
|- pom.xml --> parent pom
|+ module1/
| - pom.xml --> child pom
| - src/
|- module2/
There can be several such hierarchies. There are 2 ways to define this inheritance
Add a xml block in parent pom to tell it which are the dependent modules. OR
Add a xml block in a module to tell whose is it's parent. (This is your case)
This means that, the child pom is dependent on parent and will try to find the the concerned artifact with 0.45-SNAPSHOT version. This version has changed probably due to a newer build of parent has taken place replacing the version.