unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
122 stars 42 forks source link

java.lang.ClassCastException: class tec.units.indriya.unit.ProductUnit cannot be cast to class tec.uom.se.AbstractUnit (tec.units.indriya.unit.ProductUnit and tec.uom.se.AbstractUnit are in unnamed module of loader 'app') #158

Closed Azbesciak closed 6 years ago

Azbesciak commented 6 years ago

Guys, tell me what I suppose to do- I have multiproject build in gradle,In one I am using geotools 20.0 which uses :

si.uom:si-quantity:0.7.1
uom:si-units-java8:0.7.1
systems.uom:systems-common-java8:0.7.2
tec.uom.lib:uom-lib-common:1.0.2
tec.uom:uom-se:1.0.8

In another, I am using [Physikal SI Units kotlin extension](compile group: 'org.tenkiv.physikal', name: 'si-units', version: '2.0.2.0' ) which uses:

si.uom:si-quantity:0.9
si.uom:si-units:0.9
tec.units:indriya:1.0
tec.uom.lib:uom-lib-common:1.0.2

For last 5 hours I struggle with following error during classes initialization: class tec.units.indriya.unit.ProductUnit cannot be cast to class tec.uom.se.AbstractUnit (tec.units.indriya.unit.ProductUnit and tec.uom.se.AbstractUnit are in unnamed module of loader 'app')

I have tried to manualy manage my dependencies, finished at

implementation(group: 'org.geotools', name: 'gt-shapefile', version: '20.0') {
        exclude group: 'si.uom'
        exclude group: 'tec.uom'
}
compile (group: 'si.uom', name: 'si-units', version: '0.9') // higher version, but only changes 
compile (group: 'tec.uom', name: 'uom-se', version: '1.0.8')

... and no Ideas what to do farther. So, tell me, how should I manage those self discovery services etc? I am using Java 11 and gradle 4.10.2, but all modules are anonymous.

Azbesciak commented 6 years ago

Finished with

compile systems.uom:systems-common-java8:0.8'

in shared module,

implementation(group: 'org.tenkiv.physikal', name: 'si-units', version: '2.0.2.0') {
    exclude group: 'si.uom'
    exclude group: 'tec.uom'
    exclude group: 'tec.uom.lib'
}

and

implementation(group: 'org.geotools', name: 'gt-shapefile', version: '20.0') {
       exclude group: 'systems.uom'
 }

But anyway would want to know the answer as long as this spaghetti didn't blow up.

desruisseaux commented 6 years ago

I have not investigated above issue, but just for information: if you are using GeoTools for coordinate transformations, Apache SIS is a better alternative and is bundled with its own JSR-363 implementation (should not conflict with other implementations if you have many on the classpath). If you are using GeoTools for reading ShapeFiles, then unfortunately SIS is not yet ready for that.

keilw commented 6 years ago

So does gt-shapefile 20.0 use all of these dependencies:

si.uom:si-quantity:0.7.1
uom:si-units-java8:0.7.1
systems.uom:systems-common-java8:0.7.2
tec.uom.lib:uom-lib-common:1.0.2
tec.uom:uom-se:1.0.8

Or is your project using them together with gt-shapefile? I know, Physikal already upgraded to Indriya and SI/System Units 0.9 which are based on Indriya and not UOM-SE. So with the older dependencies this leads to the mentioned conflict. I can't say, if using SIS in your own code would help you or allow to convert between different frameworks, I have reasonable doubt, it would work. If the mentioned 0.7 versions of SI/Systems are in your actual codebase, would it be possible to upgrade that to 0.9? Then there should be no mismatch.

Azbesciak commented 6 years ago

I upgraded geotools to 20.0 yesterday, and unfortunatly, they are using 0.7.1/0.7.2 (all of mentioned above) ... I tried manualy manage 0.9, but with mentioned earlier result.

keilw commented 6 years ago

Then it sounds like this is up to GeoTools to fix it with a 20.1 or similar upgrade. @desruisseaux Any chance to help with that? The only temporary fix I could think of is changing the version of Physikal to something between 1.0 and 1.1, see https://search.maven.org/search?q=g:org.tenkiv.physikal%20AND%20a:core&core=gav or https://search.maven.org/search?q=g:org.tenkiv.physikal%20AND%20a:si-units&core=gav that uses the same SI and Unit Systems versions and is still based on uom-se. Physikal up to 1.1.3.4 looks about right.