Skip to content

Commit cb51f83

Browse files
authored
Best effort at resolving or documenting JNA dependency issues (oshi#1091)
* Document jna version override for Spring Boot * Add JNA to dependencyManagement
1 parent 5e7fcbf commit cb51f83

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

FAQ.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ What minimum Java version is required?
2424
========
2525
OSHI 3.x is compatible with Java 7, but will not see any added features.
2626
OSHI 4.x and 5.x (planned) require minimum Java 8 compatibility, although backporting to Java 7 would not be difficult on a fork.
27-
OSHI 6.x's requirements have not yet been finalized but will likely require at least Java 11.
27+
OSHI 6.x's requirements have not yet been finalized but will likely require at least Java 11 and leverage modules.
2828

2929
Which operating systems are supported?
3030
========
@@ -34,6 +34,13 @@ OSHI has been implemented and tested on the following systems. Some features ma
3434
* Linux (Most major distributions) Kernel 2.6 and higher
3535
* Unix: Solaris 11 (SunOS 5.11) / FreeBSD 10
3636

37+
How do I resolve JNA `NoClassDefFound` errors?
38+
========
39+
OSHI uses the latest version of JNA, which may conflict with other dependencies your project (or its parent) includes. If you experience issues with `NoClassDefFound` errors for JNA artifacts, consider one or more of the following steps to resolve the conflict:
40+
- Listing OSHI earlier (or first) in your dependency list
41+
- Specifying the most recent version of JNA as a dependency
42+
- If you are using a parent (e.g., Spring Boot) that includes JNA as a dependency, override the `jna.version` property
43+
3744
What API features are not implemented on some operating systems?
3845
========
3946
The following generally summarizes known exceptions. If you have missing data that is not on this list, please report it in an issue so we can investigate.

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ Downloads
6262

6363
Usage
6464
-----
65-
We strongly recommend you use a dependency manager such as Maven or Gradle. You can [find the appropriate syntax to include OSHI here](https://search.maven.org/artifact/com.github.oshi/oshi-core/4.3.0/jar). This will add the transitive dependencies. If you experience issues with `NoClassDefFound` errors for JNA artifacts, you might have another dependency to JNA which resolves first. Listing OSHI earlier in your dependency list will usually resolve this, or you may try manually specifying the most recent version of JNA.
65+
Include OSHI and its dependencies on your classpath. We strongly recommend you add OSHI as a dependency to your project dependency manager such as Maven or Gradle. You can [find the appropriate syntax to include OSHI here](https://search.maven.org/artifact/com.github.oshi/oshi-core/4.3.0/jar).
6666

6767
Create a new instance of `SystemInfo` and use the getters to access additional information.
6868

6969
You can run the [SystemInfoTest](https://github.com/oshi/oshi/blob/master/oshi-core/src/test/java/oshi/SystemInfoTest.java)
70-
and see the full output for your system by cloning the project and building it with [Maven](http://maven.apache.org/index.html).
70+
and see the full output for your system by cloning the project and building it with [Maven](http://maven.apache.org/index.html):
7171

7272
```
7373
git clone https://github.com/oshi/oshi.git && cd oshi
@@ -77,6 +77,11 @@ git clone https://github.com/oshi/oshi.git && cd oshi
7777
-Dexec.classpathScope="test"
7878
```
7979

80+
Note: OSHI uses the latest version of JNA, which may conflict with other dependencies your project (or its parent) includes. If you experience issues with `NoClassDefFound` errors for JNA artifacts, consider one or more of the following steps to resolve the conflict:
81+
- Listing OSHI earlier (or first) in your dependency list
82+
- Specifying the most recent version of JNA as a dependency
83+
- If you are using a parent (e.g., Spring Boot) that includes JNA as a dependency, override the `jna.version` property
84+
8085
OSHI for enterprise
8186
-------------------
8287
Available as part of the Tidelift Subscription

oshi-core/pom.xml

+21-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
SOFTWARE.
2525
2626
-->
27-
<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">
27+
<project xmlns="http://maven.apache.org/POM/4.0.0"
28+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
29+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2830
<modelVersion>4.0.0</modelVersion>
2931

3032
<parent>
@@ -46,20 +48,36 @@
4648
</scm>
4749

4850
<properties>
51+
<!-- Users of the Spring Boot Starter Parent should include this property
52+
in their POM -->
4953
<jna.version>5.5.0</jna.version>
5054
<main.basedir>${project.parent.basedir}</main.basedir>
5155
</properties>
5256

57+
<dependencyManagement>
58+
<dependencies>
59+
<!-- Due to critical nature of OSHI jna usage, set to dependency management
60+
to help influence usage -->
61+
<dependency>
62+
<groupId>net.java.dev.jna</groupId>
63+
<artifactId>jna</artifactId>
64+
<version>${jna.version}</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>net.java.dev.jna</groupId>
68+
<artifactId>jna-platform</artifactId>
69+
<version>${jna.version}</version>
70+
</dependency>
71+
</dependencies>
72+
</dependencyManagement>
5373
<dependencies>
5474
<dependency>
5575
<groupId>net.java.dev.jna</groupId>
5676
<artifactId>jna</artifactId>
57-
<version>${jna.version}</version>
5877
</dependency>
5978
<dependency>
6079
<groupId>net.java.dev.jna</groupId>
6180
<artifactId>jna-platform</artifactId>
62-
<version>${jna.version}</version>
6381
</dependency>
6482
</dependencies>
6583
</project>

0 commit comments

Comments
 (0)