-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds documentation for dealing with modules
- Loading branch information
Showing
5 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
docs/_errormessages/class-or-field-is-not-accessible-jpms.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: "Class or field is not accessible via the Java Module System" | ||
--- | ||
The class is not accessible via the Java Module system. | ||
Consider opening the module that contains it. | ||
|
||
<br/> | ||
|
||
Field foo of type Bar is not accessible via the Java Module System. | ||
Consider opening the module that contains it, or add prefab values for type Bar. | ||
|
||
Either the class that EqualsVerifier is testing, or one of its fields, cannot be accessed due to restrictions from the Java Platform Module System. | ||
|
||
If it's the class that EqualsVerifier is testing, you must modify your `module-info.java` such that the package containing the class, is accessible for reflection via the `open` keyword. | ||
|
||
If it's one of the fields in the class, you can either modify your `module-info.java` as above, or add prefab values for the given type: | ||
|
||
|
||
{% highlight java %} | ||
EqualsVerifier.forClass(TheClassThatImTesting.class) | ||
.withPrefabValues(Bar.class, new Bar(1), new Bar(2)) | ||
.verify(); | ||
{% endhighlight %} | ||
|
||
See also the [section in the manual](/equalsverifier/manual/jpms) about modules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: 'Unable to make field foo accessible: module bar does not "opens bar" to baz' | ||
--- | ||
This error message occurs in older versions of EqualsVerifier. If you upgrade, the error message wil probably be replaced with "The class is not accessible via the Java Module system" or "Field foo of type Bar is not accessible via the Java Module system". If so, please check [that error message](/equalsverifier/errormessages/class-or-field-is-not-accessible-jpms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: "The Java Platform Module System" | ||
permalink: /manual/jpms/ | ||
--- | ||
EqualsVerifier is compatible with the Java Platform Module System (JPMS). However, since it does some reflection, you have to open up some packages. Perhaps you have already done so, as test frameworks like JUnit also require this. | ||
|
||
The recommended approach is to put a `module-info.java` file in your `src/test/java` folder, that copies the content the `module-info.java` file in `src/main/java`. Let's say this is your `src/main/java/module-info.java`: | ||
|
||
{% highlight java %} | ||
module my.module { | ||
exports my.module; | ||
} | ||
{% endhighlight %} | ||
|
||
The easiest way to use EqualsVerifier, is to put this `module-info.java` in your `src/test/java` folder: | ||
|
||
{% highlight java %} | ||
open module my.module { // Note: open | ||
exports my.module; // Same as before | ||
|
||
requires org.junit.jupiter.api; // For JUnit | ||
requires nl.jqno.equalsverifier; // For EqualsVerifier | ||
requires net.bytebuddy; // Dependency of EqualsVerifier | ||
} | ||
{% endhighlight %} | ||
|
||
Note that this approach opens up the entire module for reflection. If you do not want this, even in your tests, you can be more precise in what you open up: | ||
|
||
{% highlight java %} | ||
open module my.module { | ||
exports my.module; | ||
opens my.module.package.model; // Open model package | ||
|
||
requires org.junit.jupiter.api; | ||
requires nl.jqno.equalsverifier; | ||
requires net.bytebuddy; | ||
} | ||
{% endhighlight %} | ||
|
||
Note that if you do this, and you have model classes or dependencies for model classes in other packages, you will have to open these packages as well, or provide prefab values for these dependencies: | ||
|
||
{% highlight java %} | ||
import my.module.package.somewhere.inaccessible.Bar; | ||
|
||
EqualsVerifier.forClass(Foo.class) | ||
.withPrefabValues(Bar.class, new Bar(1), new Bar(2)) | ||
.verify(); | ||
{% endhighlight %} | ||
|
||
When the class that EqualsVerifier is testing is inaccessible, you will get this error message: | ||
|
||
The class is not accessible via the Java Module system. | ||
Consider opening the module that contains it. | ||
|
||
If the class is accessible, but the class for one of its fields isn't, you will get this error message: | ||
|
||
Field foo of type Bar is not accessible via the Java Module System. | ||
Consider opening the module that contains it, or add prefab values for type Bar. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters