Skip to content

Universal dependency to build against jdk.tools (AKA tools.jar) in a portable way

License

Notifications You must be signed in to change notification settings

olivergondza/maven-jdk-tools-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Maven jdk.tools wrapper

Universal dependency to build against jdk.tools (AKA tools.jar) in a portable way

TL;DR

When maven gives you headaches trying to use some of the tools.jar classes (because the system scoped dependency have different paths in different JDKs or does not even exist), following dependency should get you going:

    <dependency>
      <groupId>com.github.olivergondza</groupId>
      <artifactId>maven-jdk-tools-wrapper</artifactId>
      <version>0.1</version>
    </dependency>

Problem

Prior Jigsaw introduced in Java 9, maven needs to pass the jar on javac classpath at compile time to build projects referring to its classes. Despite the fact the jar is distributed together with JDK, maven needs to be instructed to use it explicitly. system dependency scope is here to do just that but there are still some caveats to keep in mind:

Solution

There are tricks to get this working across Java versions and systems. Maven profiles can distinguish those situations and declare particular dependency if needed. Consult the pom.xml for more details.

As the actual maven wizardry is quite elaborate, surprising to newcomers and a subject of future improvements, it is better not co copy-paste it around. Hence this module exists so you do not have to know or care about the details.

This dependency (hosted on maven central) do not have any runtime footprint (external dependencies, classes loaded) but merely instruct maven what to do on compile time. All the transitive dependencies brought to the client projects are system scoped.

About

Universal dependency to build against jdk.tools (AKA tools.jar) in a portable way

Resources

License

Stars

Watchers

Forks

Packages

No packages published