Pi4J / pi4j-v2

Pi4J Version 2.0
Apache License 2.0
266 stars 54 forks source link

Some classes are not importable #355

Closed bennymeg closed 2 months ago

bennymeg commented 3 months ago

It appears that some of the classes (i.e. DigitalState) are packaged after compilation (.class files) Which means that they cannot be imported.

In example:

// use a configuration builder
var ledConfig = DigitalOutput.newConfigBuilder(pi4j)
        .id("my-dout")
        .name("My LED")
        .address(PIN_LED)
        .shutdown(DigitalState.LOW)
        .initial(DigitalState.HIGH);

throws an error: Cannot resolve symbol 'DigitalState'.

Is this intentional? Can it be fixed? Tested with Pi4J v2.5.0 & v2.6.0

taartspi commented 3 months ago

I added this code to an existing testcase. Appears to work for me.

my imports include

import com.pi4j.io.gpio.digital.Digital; import com.pi4j.io.gpio.digital.DigitalInput; import com.pi4j.io.gpio.digital.DigitalOutput; import com.pi4j.io.gpio.digital.DigitalState;

var ledConfig = DigitalOutput.newConfigBuilder(pi4j) .id("my-dout") .name("My LED") .address(18) .shutdown(DigitalState.LOW) .initial(DigitalState.HIGH);

    var led = pi4j.create(ledConfig);

    logger.info("pin detail " + led);

When executed. [main] INFO com.pi4j.test.devices.dht22.GpioTest - pin detail @my-dout "My LED" (#18)

Maybe we are not trying this the same way, can you give more details ?

taartspi commented 3 months ago

Also. with 2.6.0-SNAPSHOT from my POM file Note pi4j-v2-devices is mine and not required by you. .

com.pi4j pi4j-v2-devices 0.0.1 com.pi4j pi4j-core ${pi4j.version} com.pi4j pi4j-plugin-gpiod ${pi4j.version} com.pi4j pi4j-plugin-pigpio ${pi4j.version} org.slf4j slf4j-api ${slf4j.version} org.slf4j slf4j-simple ${slf4j.version} com.pi4j pi4j-plugin-linuxfs ${pi4j.version}
bennymeg commented 3 months ago

IDE: intellij IDEA Build tool: Gradle 7.2 JVM: 17.0.2


Steps to reproduce:

It seems that small subset of the files inside the 'pi4j-core' JAR are compiled. Here is a partial list of them: Parity, StopBits, DataBits, FlowControl, DigitalState, PullResistance ... These files cannot be imported.

--- minimal test case ---

image

taartspi commented 2 months ago

I followed Pi4J website > Getting started with Pi4J > Minimal example application.

Had intellij open this trusted. This example had been updated for 2.6.0-SNAPSHOT and newer providers. So I edited it match your details.

diff --git a/build.gradle b/build.gradl dependencies { implementation 'org.slf4j:slf4j-api:2.0.12' implementation 'org.slf4j:slf4j-simple:2.0.12'

diff --git a/pom.xml b/pom.xml index 89238d1..c9b6f4f 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@

com.pi4j - pi4j-plugin-gpiod + pi4j-plugin-pigpio ${pi4j.version}
 </dependencies>

b/src/main/java/module-info.javamodule com.pi4j.example { // Pi4J MODULES requires com.pi4j;

The import works and the use of DigitalState is good.

When I try to build this ‘sudo ./gradlew build’ I hit an error General error during semantic analysis: Unsupported class file major version 65. I have not looked into this but hopefully something specific to my environment.

But I do not see your error. I am using a new java, as long as you are java 11 or newer that should not be the problem, and at least gradle 6.6

openjdk version "21.0.3" 2024-04-16 LTS

./gradlew -version


Gradle 6.6

FDelporte commented 2 months ago

FYI, minimal example is now bumped to 2.6.0

bennymeg commented 2 months ago

After a lot of testing, it appears to be a bug in IntelliJ IDEA & Gradle and not in Pi4Jv2. Upgrading to the latest releases (2024.1 & 8.7 respectively) resolve this issue.