Maven Eclipse - Child module not recognized as maven project - java

I'm working on a new maven multi module project on eclipse. The problem is, the child project is shown as a regular folder and not a maven folder. What's the problem? I created the parent project with only the pom.xml and pom packaging. the child module was created through cmd with the typical mvn archetype:generate command
here are the pom.xml files
Parent
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>blabla</groupId>
<artifactId>zuers-klassen</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>zuers-klassen-api</module>
</modules>
</project>
Child
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>zuers-klassen</artifactId>
<groupId>blbabla</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>blabla</groupId>
<artifactId>zuers-klassen-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>Archetype - zuers-klassen-api</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.2.0</version>
</extension>
</extensions>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<properties>
<https.protocols>${https.protocols}</https.protocols>
</properties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

Related

Maven - Put Dependency Into Other Dependency with Maven Assembly Plugin

I have a Maven POM project test-module3 with two dependencies: Dependency test-module1 and dependency test-module2.
Dependency test-module2 has also test-module1 as dependency with scope set to compile, but it does not have the Maven Shade Plugin or the Maven Assembly Plugin configured.
Now I want to build dependency test-module2 using test-module3. So I configure the Maven Assemby Plugin. That works great. But dependency test-module1 is missing in dependency test-module2.
How can I configure the Maven Assemby Plugin or any other plugin of test-module3 so, that it shades test-module1 into test-module2?
Here are my POMs:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>test</groupId>
<artifactId>test-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>test-distribution</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>test</groupId>
<version>${project.version}</version>
<artifactId>test-module1</artifactId>
</dependency>
<dependency>
<groupId>test</groupId>
<version>${project.version}</version>
<artifactId>test-module2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/distribution.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
distribution.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
</dependencySet>
</dependencySets>
</assembly>
POM of test-module1:
<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>
<parent>
<groupId>test</groupId>
<artifactId>test-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>test-module1</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
POM of test-module2:
<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>
<parent>
<groupId>test</groupId>
<artifactId>test-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>test-module2</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>test-module1</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
My goal is to put test-module1 in the ZIP folder and test-module2 in the ZIP folder, but test-module2 should also contain test-module1.

Spring Boot Maven multi module project with profile - packages from other module not found

I'm currently try to structure my Spring Boot Maven application with multiple pom files. I have two applications which needs to share a lot of classes. I have the following structure:
.
├── application1
| |── src
│ └── pom.xml
|── application2
| |── src
│ └── pom.xml
|── shared
| └── src
| └── pom.xml
|
└── pom.xml
The pom in the root directory looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>nl.example.parent</groupId>
<artifactId>example-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<!-- sub modules -->
<modules>
<module>application1</module>
<module>application2</module>
<module>shared</module>
</modules>
<properties>
<java.version>1.8</java.version>
<maven.plugins.version>2.22.1</maven.plugins.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.plugins.version}</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugins.version}</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>application1</id>
<modules>
<module>shared</module>
<module>application1</module>
</modules>
</profile>
<profile>
<id>application2</id>
<modules>
<module>shared</module>
<module>application2</module>
</modules>
</profile>
</profiles>
</project>
The pom in both the application1 and application2 directory look like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>nl.example.parent</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>nl.example.application1</groupId>
<artifactId>example-child</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<!-- Is this the right way to import the shared module into application1 or application2? -->
<dependency>
<groupId>nl.example.shared</groupId>
<artifactId>example-shared</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Then I have a shared module of which most classes will be shared between application1 and application2. The pom of the shared directory looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>nl.example.parent</groupId>
<artifactId>example-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>nl.example.shared</groupId>
<artifactId>example-shared</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<!-- Shared dependencies here -->
</dependencies>
</project>
However, when I try to build the specific profile for one of the two applications I get errors for every import that I try to make from the shared module. Obviously I'm doing something wrong but I can't figure out why the classes from the shared folder are not reachable when called from application1? I did include the shared module as dependency in both application1 and application2
Your Parent POM has Spring Boot as parent. But this does not work. You will not get the dependencies in your modules.
You have to configure a project that does not inherit from Spring Boot Parent and add Spring Boot dependencies to dependency management.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-maven-without-a-parent

Maven parents and childs in Intellij

In my maven project I have 1 main and 2 modules. It only compiles and runs when I add the two modules to the dependencies in the main pom.xml, otherwise I get compile errors that the reflections library etc is not found.
How can I solve this?
powercontrol.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>nl.nberlijn.powercontrol</groupId>
<artifactId>powercontrol</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>log</module>
<module>kernel</module>
</modules>
<dependencies>
<dependency>
<groupId>nl.nberlijn.powercontrol</groupId>
<artifactId>kernel</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>nl.nberlijn.powercontrol</groupId>
<artifactId>log</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
kernel.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>nl.nberlijn.powercontrol</groupId>
<artifactId>powercontrol</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>kernel</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.53</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
log.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>nl.nberlijn.powercontrol</groupId>
<artifactId>powercontrol</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>log</artifactId>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Without more details on the code inside each of your modules, it is hard to say why this is. However, by placing your two modules as dependencies in your parent POM, they and their transitive dependencies will be inherited by both child modules.
I think you should be able to resolve this by removing the dependencies from your parent POM, and adding a dependency to your log POM to depend on your kernel module.

How to exclude folder with files from war maven assembly

I wanna exclude folder marked with red line. How can I do it?
Here is my pom.xml:
<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.test</groupId>
<artifactId>Test</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<url>http://maven.apache.org</url>
<properties>
<spring-version>4.1.0.RELEASE</spring-version>
<spring-security-version>3.2.3.RELEASE</spring-security-version>
<hibernate-version>4.3.4.Final</hibernate-version>
</properties>
<dependencies>
<!-- a lot of dependencies -->
</dependencies>
<build>
<finalName>Test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Should I do anything with maven-compiler-plugin configuration?
This should give you the answer you need: http://maven.apache.org/plugins/maven-war-plugin/examples/including-excluding-files-from-war.html
Here is an example where we exclude all JAR files from WEB-INF/lib:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
This doesn't have anything to do with the maven compiler plugin, but the maven war plugin.

Maven: Unit test not running

I have a problem running unit test of a maven project.
The project used to be one pom. I split it up into three poms.
My maven is like this. There are three of these poms which looks all like this.
<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
<artifactId>client</artifactId>
<version>1.0</version>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>base-pom</artifactId>
<relativePath>../../build/shared/pom.xml</relativePath>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<forkMode>never</forkMode>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
....
</dependencies>
The top level pom is:
<groupId>com.mycompany</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>modules/shared</module>
<module>modules/client</module>
<module>modules/adapter</module>
</modules>
The parent POM, which is shared by all the modules are:
<groupId>com.mycompany</groupId>
<artifactId>base-pom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>mycompany-parent</artifactId>
<version>1.0.8</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
...
</dependencyManagement>
It uses to work when there is just one POM. What is the problem of this?
Many thanks
I would recommend to restructure your projects structure to represent the real layout of the project. I can recommend to reading this entry here on SO

Categories

Resources