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.
Related
I have a pom.xml file where I get this message Plugin 'org.apache.maven.plugins:maven-compiler-plugin:' not found. I recently started using Maven and been looking around without any answer
<?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>org.example</groupId>
<artifactId>Declarations</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My issue is with
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
maven-compiler-plugin says Plugin 'org.apache.maven.plugins:maven-compiler-plugin:' not found.
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>
When i run my project I get:
java.io.FileNotFoundException:
C:\Users\Anubhav\Desktop\QRDemo\Quote.png (The system cannot find the
path specified)
Here is my pom.xml code:
<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>QRCode</groupId>
<artifactId>QRCode</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm completely lost
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.
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