Building a project with mixed Scala and Java source files using Ant - illegal circular link error

I currently have an existing Java project with an Ant construct that I am trying to create with a mixed source (Java and Scala).

I hava a Java interface defined as - public interface One<T extends Two<? super T>>

that when I run scalac from the Ant build, I get the following error:

Error: illegal circular reference with type T.

Since I want Scala and the Java class to be interdependent in my project, I first run the scalac task before running javac in the Ant build. My scalar block is as follows:

<scalac srcdir="${src.path}" destdir="${build.classes}" encoding="UTF-8" >
        <classpath refid="compile.classpath" />
        <include name="**/*.scala"/>
        <include name="**/*.java"/>
</scalac> 

Is there any way around this? I cannot change the Java code, since there is a lot of other code that uses it.

I am using Java 7 and Scala 2.11.5


Here is what I see at the end:

com.arif.One.java

package com.arif.java;
public interface One<T extends One<? super T>> {
    void test1();
}

com.arif.Two.java

package com.arif.java;
public class Two implements One<Two> {
    @Override
    public void test1() {
    } 
}

com.arif.scala.Main.scala

package com.arif.scala
import com.arif.java.Two

object Main {
  def main(args:Array[String]) {
    var b:Two = null
  } 
}

build.xml

<property name="scala.home" value="/Users/arif/software/scala/scala-2.11.5"/>
<property name="build.classes" value="./build/classes"/>

<property name="src.path" value="src"/>
<property name="javac.target" value="1.7"/>
<property name="compile.debug" value="true" />
<property name="compile.deprecation" value="false" />
<property name="compile.optimize" value="false" />

<path id="compile.classpath">
    <fileset dir="${scala.home}/lib" includes="*.jar" />
</path>

<path id="scala.classpath">
    <pathelement location="${scala.home}/lib/scala-compiler.jar" />
    <pathelement location="${scala.home}/lib/scala-library.jar" />
    <pathelement location="${scala.home}/lib/scala-reflect.jar" />
</path>

<target name="init">
    <taskdef resource="scala/tools/ant/antlib.xml">
        <classpath refid="scala.classpath" />
    </taskdef>
</target>

<target name="build" description="build" depends="init">
    <scalac srcdir="${src.path}" destdir="${build.classes}" encoding="UTF-8" >
        <classpath refid="compile.classpath" />
        <include name="**/*.scala"/>
        <include name="**/*.java"/>
    </scalac>
    <javac srcdir="${src.path}" destdir="${build.classes}" memoryinitialsize="512m" target="${javac.target}" source="${javac.target}" 
        memorymaximumsize="1024m" nowarn="true" debug="${compile.debug}" deprecation="${compile.deprecation}" 
        optimize="${compile.optimize}" fork="true" encoding="iso-8859-1" includeantruntime="false">
        <classpath refid="compile.classpath" />
    </javac>
</target>

- "ant build" -

[scalac] Compiling 1 scala and 2 java source files to /Users/arif/rbc/scala-java/build/classes
[scalac] /Users/arif/rbc/scala-java/src/com/arif/java/One.java:3: error: illegal cyclic reference involving type T
[scalac] public interface One<T extends One<? super T>> {
[scalac]                                    ^
[scalac] one error found
+4
2

PR SI-4744 -Ybreak-cycles, .

+2

, - scala ( java- scalac):

scala> class OneImpl[T <: Two[_ >: T]] extends One[T]
<console>:15: error: illegal cyclic reference involving type T
   class OneImpl[T <: Two[_ >: T]] extends One[T]

Java- ( Ant). :

scala> class OneImpl[Z >: T, T <: Two[Z]] extends One[T] 
defined class OneImpl

scala . ( ):

scala> class OneImpl[Z >: T, T <: Two[Z], K <: Two[_ >: Z]](implicit  ev: K =:= T) extends One[T]
defined class OneImpl

. http://www.scala-lang.org/old/node/6358

. scalac SI-4744. , . ( ) javac:

javac One.java

- ant:

<target name="build" description="build" depends="init">
    <javac srcdir="${src.path}" destdir="${build.classes}" encoding="UTF-8">
        <classpath refid="compile.classpath" />
        <include name="**/One.java"/>
    </javac> 
    <scalac srcdir="${src.path}" destdir="${build.classes}" encoding="UTF-8" >
        <classpath refid="compile.classpath" />
        <include name="**/*.scala"/>
        <include name="**/*.java"/>
        <exclude name="**/One.java"/>
    </scalac>
    <javac>...</javac>
</target>
+1

All Articles