unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
118 stars 40 forks source link

Compile-time error when using custom unit #267

Closed Eurybiadan closed 4 years ago

Eurybiadan commented 4 years ago

I am using Indriya 2.0.1 via Maven and am getting an error at compile time wherever I instantiate a custom unit; for example, if I create a "pixel" unit:

Unit<Dimensionless> PIXEL = new BaseUnit<Dimensionless>("px","pixel");

This leads to the error:

Error: cannot access tech.uom.lib.common.function.PrefixOperator
  class file for tech.uom.lib.common.function.PrefixOperator not found

Any advice would be appreciated.

keilw commented 4 years ago

It sounds like the POM of your project could be missing dependencies. Would you be able to share some more about the setup with us?

This very simple demo project shows the minimal dependencies and uom-lib-common is also part of it: https://github.com/unitsofmeasurement/uom-demos/blob/master/console/basic/pom.xml

Eurybiadan commented 4 years ago

IntelliJ tells me that uom-lib-common is already added as a dependency, but even adding it explicitly doesn't fix it.

My pom originally included just the line (per your uom-guide):

<dependency>
            <groupId>tech.units</groupId>
            <artifactId>indriya</artifactId>
            <version>2.0</version>
        </dependency>

But in order to get both SI and USCustomary unit I added.

        <dependency>
            <groupId>systems.uom</groupId>
            <artifactId>systems-common</artifactId>
            <version>2.0</version>
        </dependency>

It's important to note that moving to 2.0.1 does not fix my issue.

Eurybiadan commented 4 years ago

I also use junit jupiter:

<dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.4.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.2</version>
            <scope>test</scope>
        </dependency>
Eurybiadan commented 4 years ago

It's also important to note that if I create a new project, and place just

            <dependency>
            <groupId>tech.units</groupId>
            <artifactId>indriya</artifactId>
            <version>2.0</version>
        </dependency>

In my pom and the line above into a java file, there are no issues compiling. So I'm guessing there's a conflict somewhere...

Eurybiadan commented 4 years ago

Ugh, I found it and fixed it. Turns out my classpath didn't auto-update to include the dependencies of indriya. Sorry for clogging your issues feed.