Recently, I came accross the following problem :
As I set up dependency management for my project, I had child-pom using plugin with dependencies, that I want to be synchronized with dependencies declared in my dependency management.
In a root pom, I declared in my dependency management:
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
<dependencies>
<dependencyManagement>
And in the child pom, I have a plugin which needs gwt-user :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
</dependencies>
...
</plugin>
However, if I remove the dependency version used in gwt-maven-plugin, the compilation fails.
Is there another way to achieve it ?
PS: There is a related post Choosing dependency version in maven and maven plugin which does not answer my question
According to the following links, it seems not to be possible:
http://maven.40175.n5.nabble.com/dependency-management-within-plugin-dependencies-td78367.html
https://issues.apache.org/jira/browse/MNG-2496
Here is a workaround I found, and I wanted to share with everyone, in case other people had the same problem:
In my root pom, I have defined a property, a dependency management and a plugin management:
<properties>
<gwtVersion>2.4.0</gwtVersion>
<gwtMavenPluginVersion>2.4.0</gwtMavenPluginVersion>
</properties>
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtMavenPluginVersion}</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
...
</plugins>
...
</pluginManagement>
</build>
And in my child pom, using the relationship provided by plugin management (see Maven2 - problem with pluginManagement and parent-child relationship), I just declare the plugin dependency:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
</plugin>
Now if I change the version in the properties, it is automatically impacting all direct dependencies and plugin dependencies.
For a parent POM to control which plugin versions the child uses, you should declare the <plugin> in a <pluginManagement> section of the parent POM.
You defined com.google.gwt:gwt-user as a <dependency> in the <dependencyManagement> section.
I'm not sure if you are intending to use gwt-user as a plugin or as a dependency, but it should be listed as the same entity in both for inheritance to work.
The other possibility is to import all the dependencies of the parent POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
...
</plugin>
Not the most beautiful solution, but working :-)
In my case I was using the jetty maven plugin, with a dependency on hsqldb. I copied some sample lines from the sonatype book (I think that's where I got the lines from) for using the jetty plugin, which specified the groupId as hsqldb. I am using version 2.3.2 of hsqldb. In my parent pom in the dependencyManagement section and my persistence module the groupId is org.hsqldb. Having mismatched groupIds was what was causing me to get an error, because under that old groupId there isn't a version 2.3.2. Once I changed the groupId from hsqldb to org.hsqldb everything started working.
Related
I have a maven project with modules. The parent for my root project is spring-boot-starter-parent, which provides a lot of dependency management.
In my module, I use spring-boot-configuration-processor, which is one of the dependencies managed by spring-boot-starter-parent (well, actually managed by its parent, spring-boot-dependencies).
If I don't specify the version in the plugins section, my build fails with:
Resolution of annotationProcessorPath dependencies failed: For artifact {org.springframework.boot:spring-boot-configuration-processor:null:jar}: The version cannot be empty. -> [Help 1]
So, I am forced to have the plugins section look like this:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.6.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
However, I would prefer to reference the inherited version. Although spring-boot-dependencies has a lot of properties for the versions of various dependencies, it does not have a property for the version of spring-boot-configuration-processor. Nor does it include spring-boot-configuration-processor in plugin management.
How do I use the inherited version of this plugin instead of having to explicitly specify the version myself?
I do believe instead of configuring maven-compiler-plugin you just need to declare spring-boot-configuration-processor as a dependency of your project with scope=provided - the purpose of annotationProcessorPaths and annotationProcessors parameters of maven-compiler-plugin is not to add annotation processor, but to force the compiler to use defined annotation processors only.
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
...
</plugins>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>
You need to inherit from parent POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{YOUR_VERSION}</version>
</parent>
I am using the Eclipse IDE and in the past, I have been developing a maven project depending on local sources (from github (sap-olingo)) as well as maven dependencies loaded as jar. I have now updated the github source and also all the dependencies which seems to break standard eclipse export functionalities (right click porject -> export -> war)
The webproject is working fine when using the maven install functionality and is loading all sources into the META-INF/lib classes, but when using the export as war from eclipse (which I did previously) it is missing to compile a proper dependency. Missing in the sense of that the jar is still present in the META-INF/lib directory of the war, but the content is empty and the size is only 1kb
When comparing the mvn clean install to the exported, there are rarely any differences. Except for the projects that are to be compiled during the runtime. Sizes of the libs in the mvn created war and the exported war roughly matches except for that one jar.
Is there a way to root cause that issue? I am using solely the maven integrated into the IDE which is why I doubt differences in the maven versions and or jdk.
Unfortunately I have no idea in where to start and what info you require
Thanks for your input
EDIT:
My projects pom:
<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>odata</artifactId>
<packaging>war</packaging>
<version>4.0.0</version>
<name>odataMaven Webapp</name>
<url></url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.olingo</groupId>
<artifactId>odata-jpa-processor</artifactId>
<version>0.3.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<finalName>odata</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${project.build.source}</source>
<target>${project.build.source}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.source>1.8</project.build.source>
</properties>
</project>
The odata-jpa-processor source/project is pulled from here. The problem exists solely with the olingo-jpa-metadata jar which is empty. All other maven dependencies are exported correctly.
I am a beginner in Java coding, I am teaching myself JavaFX and making a project that uses JPA through Hibernate (I have no knowledge on Spring yet).
The problem I find myself having is that an essential external library doesn't have a module-info for me to refer to in my project.
I can have either JavaFX or mysql-connector-java working, but not both at the same time.
The connector I am using is: https://mvnrepository.com/artifact/mysql/mysql-connector-java version 8.0.19
When I exclude my module-info my JPA works, when I use my module-info my FX works
I asked my teacher for help but he doesn't seem to have an idea yet on how I can use my JavaFX and JPA in the same project. Does anyone have a good suggestion on how I can fix this issue?
My POM
<?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.tumblr.calscodingcorner</groupId>
<artifactId>dnd5e_database_maker</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.tumblr.calscodingcorner.application.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx</artifactId>
<version>11</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
</dependencies>
My module.info
module dnd5e.database.maker {
requires javafx.controls;
requires java.persistence;
requires mysql.connector.java;
exports com.tumblr.calscodingcorner.application;}
Thanks in advance for any advice
Answering the title:
module-info when one of my external libraries doesn't have a module-info
You need to require (in module-info.java) the automatic module name corresponding to the name of the dependency jar (without the version), or to the Automatic-Module-Name declared in the jar's MANIFEST (if exists). Then maven will automatically add the jar to --module-path.
If you don't require the jar inside module-info, it will be added to --classpath in which case it will become part of the unnamed module and won't be visible by your module (only by automatic modules).
You can add -X to maven to see which dependencies are added to -classpath and which to --module-path
See the spec
[...] A named module cannot, in fact, even declare a dependence upon the unnamed module. This restriction is intentional, since allowing named modules to depend upon the arbitrary content of the class path would make reliable configuration impossible
I am using Maven for one of our projects. We have a compile-time plugin, jasperreports-plugin, that is built using jasperreports 6.1.1. However, we have another dependency (which we control), jasper-including-artifact, that uses jasperreports 6.1.0. This requires us to manually override the version of the jasperreports in the section for the jasperreports-plugin so they match up. What the POM ends up looking like:
<dependencies>
<dependency>
<groupId>com.my.application</groupId>
<artifactId>jasper-including-artifact</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>2.2</version>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
This works, but to make it more maintainable we'd ideally like to be able to read a value from our jasper-including-artifact dependency and use that to set the version of the overriding dependency in jasperreports-plugin, so we don't need to make manual modifications to the POM when the version of jasperreports in jasper-including-artifact is changed. So something like this (obviously fake):
<dependencies>
<dependency>
<groupId>com.my.application</groupId>
<artifactId>jasper-including-artifact</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>2.2</version>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasper-including-artifact.jasper-version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Note that it's not the version of the jasper-including-artifact we're interested in, but the version of jasperreports contained inside it. We control jasper-including-artifact so we can make changes to the POM for that if required.
Is this a capability that Maven offers?
I would like to use the Fluido skin for my Maven-based project.
If I add it only in src/site/site.xml the mvn site fails because the artifact is missing. It ask to manually install the artifact, but I would like to avoid that step for my colleagues.
I've added the following dependency to my pom.xml:
<dependency>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.2.2</version>
</dependency>
And it seems to work: the skin is automatically downloaded by maven when I do mvn site. However I do not want that my project be marked as a dependency of that artifact ; I don't want that package to be in the classpath during compile, test, etc.
I don't see any dependency scope that would restrict the dependency just for site:site.
Did I miss something about dependency scope? Is using dependency for that relationship the right thing?
I do not have time to try this myself, but I think the following should work:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
</project>