Does maven add all dependencies to modulepath by default? - maven

I read on Java 9 Modularity book:
Dependencies are always put on the module path, even when dependency isn't modularized yet.
[...]
The most important changes made to Apache Maven for support of the Java module system are as follows:
Uses the modulepath during compilation
Supports a mix of explicit modules and automatic modules as dependencies
I'm looking at maven documentation and I cannot find this information anywhere.
Does maven by default add <dependencies> to the modulepath (only?) and if yes, after which maven version?
Also if the above is true is there a way to instruct maven to not use modulepath at all?

No, Maven puts dependencies to module path only for those Maven modules that have module descriptors (module-info.java). Non-modular Maven modules still put their dependencies to classpath.
You can run Maven with -X option to see exact command-line options that are passed to javac.

Related

When Java 9 module system integrate into Maven, how to handle automatic module

I have already practiced java 9 module system integration with Maven project. and it seems to work well but I was anxious about backward compatibility of maven module compiled before java 9.
For backward compatibility, JPMS(Java Platform Module System) has Automatic Module Concept. In JPMS, Jar file without module-info.java is regarded as Automatic Module and other java module can use this jar file by using its file name as module name.
In case of integration with maven project, I think additional support for JPMS backward compatibility needed.
first, basic jar file and maven jar file is not same structure.
second, maven jar file naming is incompatible with rule can be compatibility with JPMS module naming rule. see the below example.
<artifactId>previous-version-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
In above cases, We already uses previous-version-module-0.0.1-SNAPSHOT and want to use this module in new java 9 maven project.
module new.module{
requires previous-version-module-0.0.1-SNAPSHOT
}
but it occur compile error or IDEA tool throw error.
I'm wondering how to use maven jar file which compiled before java 9 in java 9 and maven integration project.
I searched some additional module definition rule or maven plugin, I can't find any solution.
Thanks.
If the module name isn't obvious then you can use jar --file=<jarfile> --describe-module to see the derived name. Alternatively, use the --list-modules option, i.e. java -p <jarfile> --list-modules.
Once you know the module name then you use requires <module> and it should work. The maven-compiler-plugin puts all dependences on the module path when building a project that has a module-info.java in the source tree.

Release a Maven POM without expanding a variable

I've got a dependency on tools.jar in my project, which is a javac plugin. It can be configured to be run in a Maven build. So there's a maven plugin to enable a javac plugin.
This can be done by following the Maven FAQ:
http://maven.apache.org/general.html#tools-jar-dependency
includes
<systemPath>${java.home}/../lib/tools.jar</systemPath>
The problem is that the mvn release pom expands all variables, so when I've released my maven plugin, it refers to a hardcoded jdk path from the machine where the release was performed, rather than a variable to resolve it at runtime on the client machine.
That obviously causes my Maven plugin to fail to include tools.jar on the classpath.
I can't find any way to convince the maven release plugin to leave this variable in the output. Any ideas?
Bug reference: https://code.google.com/p/error-prone/issues/detail?id=18

Netbeans: maven dependencies of type pom

I've spent a lot of time and my head is blowing up already so I'll be very thankful for any help.
I'm migrating Netbeans Platform application from ant to maven, and so I'm changing all the jars in my version control repo to maven dependencies. I've found needed artifact in main maven repo and I've added it as a dependency with a help of Netbeans, but it's of type POM and was placed in Non-classpath Dependencies and I have no idea how to use it as it wasn't added to classpath etc…
Can someone explain what are these POM dependencies and how to use them?
Thank you in advance!!
EDIT
here is dependency definition in pom.xml
<dependency>
<groupId>com.kitfox.svg</groupId>
<artifactId>svg-salamander</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
Adding a pom dependency only pulls down transitive dependencies, that is jar dependencies defined as dependencies in the pom. The pom does not get added on the classpath for obvious reasons, but the transitive dependencies reachable from pom will be added to classpath.
What you ideally need to do is have dependencies of type jar Default dependency type is jar and you can simply define dependencies without any type element in the dependency section.
If you have located the jar files you need in Maven Cental, then you simply need to provide groupId artifactId and version for each one of those in dependencies section.
Personally I cannot think of any case when one would need to add pom type dependency. I usually use pom packaging for parent module in a project (specify common project configuration like plugin versions, common dependencies, like log4j for example, repositories, properties etc.) and for utility package module (the one that assembles the project and does some other necessary things).
Judging from my experience (I did it several times), when migrating project from ant to maven you should take all the jar files that your project used to depend on and convert them into maven dependencies (groupId:artifactId:version). Most probably all of these dependencies will not have any <type> (e.g. be jars).

How can I get list of plugin dependencies?

It is said that:
Maven 2.0.9 introduced the ability to override a dependency used by a
plugin. This is handy when you want to use a newer checkstyle, pmd,
etc jar than is included by default in the plugin.
My question is - how can I get list of dependencies of some specific plugin just as easy as I can get list of dependencies of the project?
Executing mvn dependency:resolve-plugins will provide a list of all the plugins defined within your POM (and those inherited from any parent POMs) along with all the dependencies of each plugin.

Impose build order for a multi-project in Maven

I have a multi project in maven like this:
paren-project
-> plugin-project
-> testbed-project
The plugin project generates a JAR, which is manually copied to a specific subdirectory of testbed (using whatever embedded script like groovy or ant). The important point: I don't want the plugin JAR to be in the classpath of testbed.
But I cannot found the solution to force the plugin project to be build BEFORE the testbed project. If I set the plugin project as dependency of the testbed project, it is added in the classpath.
Any solution, or do I have to switch to a build system like gradle, ivy or ant ?
As it is mentioned at the http://maven.apache.org/guides/mini/guide-multiple-modules.html
Reactor Sorting
Because modules within a multi-module build can depend on each other,
it is important that The reactor sorts all the projects in a way that
guarantees any project is built before it is required.
The following relationships are honoured when sorting projects:
project dependency on another module in the build
plugin declaration where the plugin is another modules in the build
plugin dependency on another module in the build
build extension declaration on another module in the build
the order declared in the modules element (if no other rule applies)
Note that only "instantiated" references are used - dependencyManagement
and pluginManagement elements will not cause a change to the reactor sort order
Maven is a versatile system. No need to switch.
You can add the dependency like this:
<dependency>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<optional>true</optional>
</dependency>
This way, the dependency will not be included in the classpath.
Read more about Optional Dependency

Resources