Adam Gent
Adam Gent

Reputation: 49095

Mixing AspectJ and Scala in an Eclipse Project

Any one been able to get a Scala and AspectJ (AJDT) to play nicely together in Eclipse 3.6?

It seems Scala's weaver conflicts with AspectJ's weaver. I'm hoping I'm just missing something.

Edit: Play nicely in the same project

Upvotes: 5

Views: 1727

Answers (4)

ruediste
ruediste

Reputation: 2959

I've been struggling with this for some time now. Here is my Solution:

First, separate your Scala and your AspectJ code into different projects.

Then add an Ant builder to your Scala project. It runs whenever the scala builder runs and does the weaving. It uses ant4eclipse to extract the classpath, but you'll have to supply the location of the scala library.

Build.xml:

<project name="simple-example" default="compile"
xmlns:ant4eclipse="antlib:org.ant4eclipse"
         xmlns:antcontrib="antlib:net.sf.antcontrib">

<ant4eclipse:jdtClassPathLibrary name="org.scala-ide.sdt.launching.SCALA_CONTAINER">
  <fileset file="../lib/scala-library.jar"/>
</ant4eclipse:jdtClassPathLibrary >

<ant4eclipse:getJdtClassPath 
    workspacedirectory=".."
    projectName="lpfExample"
    property="classpath"/>

<target name="compile">
    <iajc sourceroots="src" destdir="bin">
        <inpath>
            <pathelement location="bin" />
        </inpath>
        <aspectpath>
            <pathelement location="../aspects/bin"/>
        </aspectpath>
        <classpath path="${classpath}"/>
    </iajc>
</target>
</project>

Upvotes: 0

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

Based on your comment above, it looks like you want a single project to use both the AspectJ builder and the Scala builder. This is not possible. Each one delegates to its own compiler and the two compilers are not (yet) compatible. The Scala compiler can build Java and Scala code together, and the AspectJ compiler can build AspectJ and Java code together, but that's it.

If you want aspects to apply to your Scala code, you must separate your AspectJ and Scala code into different projects and then add the Scala project to the inpath of your AspectJ project.

This is the same thing that you would need to do if you were compiling from ant or the command line.

Upvotes: 3

Matt R
Matt R

Reputation: 10533

Do you mean having both the Scala plug-in and AJDT installed simultaneously? This is definitely doable -- it's needed for developing the Scala plug-in itself, for example.

I do the following:

  • Install the AspectJ dev tools + eclipse weaving service feature
  • Install Scala IDE, but omit JDT Weaving for Scala

Upvotes: -1

VonC
VonC

Reputation: 1327634

Right now, the recommended version is still Eclipse3.5.2.

Tickets like 1000075 or 3251 mention:

If you're desperate there's an experimental nightly build update site at http://download.scala-ide.org/nightly-update-wip-helios-2.8.0.final.

Today, the current nightly you could try with Helios 3.6 would be:

http://download.scala-ide.org/nightly-update-master-2.8.1.final

Upvotes: 2

Related Questions