tags:

views:

55

answers:

1

I get compile errors when compiling valid code against a Java model enhanced with JDO. I am confused at the errors because there is no direct usage of the package private static member interfaces in question from Scala. I understand Scala doesn't support using such interfaces from Scala code, but I am confused that the Scala compiler complains about them.

Here is the error I am getting:

[scalac] Compiling 3 scala and 196 java source files to /home/alain/Documents/Project/build/model/src
[scalac] error: error while loading Error, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/error/Error.class)
[scalac] error: error while loading Binder, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/attachment/Binder.class)
[scalac] error: error while loading Journal, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/note/Journal.class)
[scalac] error: error while loading Exemption, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/exemption/Exemption.class)
[scalac] error: error while loading Flag, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/flag/Flag.class)
[scalac] error: error while loading ConfigurationGroup, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/configuration/ConfigurationGroup.class)
[scalac] error: error while loading IssueConfiguration, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/analysis/configuration/IssueConfiguration.class)
[scalac] 7 errors found

Here is the Ant snippet I use to compile:

<target name="compile" depends="jar">
    <depend srcdir="src" destdir="${src.classes.dir}" cache="${build.dir}/src_dependencies" />
    <scalac srcdir="src" destdir="${src.classes.dir}" classpathref="src.build.classpath">
        <include name="**/*.scala"/>
        <include name="**/*.java"/>
    </scalac>
    <javac srcdir="src" destdir="${src.classes.dir}" source="1.6" target="1.6" nowarn="on"
       debug="on" encoding="UTF-8" classpathref="src.build.classpath" />
</target>

model.jar with the enhanced classes is on src.build.classpath.

I don't understand why scalac cares about dependencies of Java classes it can't resolve if they don't affect the knowledge to compile my Scala source.

Interestingly IntelliJ's Scala Plug-in is able to compile and run this code.

+1  A: 

Keep the enhanced code out of the scalac build classpath. You will still need the unenhanced code in order to compile though.

Here is how I solved this:

  1. Alter the regular JAR name to model-api.jar (inherited target uses src.classes.dir)

  2. I made the build of dependencies use model-api.jar instead of model.jar in src.build.classpath

Here is a summary of the enhance target:

<property name="production.enhanced.dir" value="${production.classes.dir}/../enhanced" />
<copy todir="${production.enhanced.dir}">
    <fileset dir="${production.classes.dir}" />
</copy>
<jdodoclet ...>
<jdoc ...>
<jar destfile="dist/model.jar"> <fileset dir="${production.enhanced.dir}" />
    <fileset dir="src" excludes="**/*.java */.jj */.scala */.groovy" />
</jar>

The notable editions I had to make were copying the unenhanced classes to an sandbox directory, running the JDO enhancement on the sandbox directory and producing a runtime JAR with the original name.

Alain O'Dea