This page is no longer maintained — Please continue to the home page at www.scala-lang.org

compile with mvn, using the compiler

3 replies
Niels Boldt
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Hi

I'm trying to compile the following code using maven and the maven/scala plugin

package mine

 import scala.tools.nsc.{Global, Settings}
 import scala.tools.nsc.reporters.ConsoleReporter

etc ..

and I get the following error. The code compiles fine using scalac or using the eclipse plugin for scala. The problem is that it misses a reference to the scala-compiler.jar. I have tried adding it as a normal dependency in maven, eg something like

    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>2.7.2</version>
    </dependency>

where I have the jar installed on my local machine, however the plugin seems to ignore the dependency. Should I add dependencies in some special way when using scala/maven or should the compiler.jar be included automatically. I have grabbed the pom from the 'Lift' project



[INFO]    task-segment: [clean, compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\temp\liftscala\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:compile {execution: default}]
[WARNING] you don't define org.scala-lang:scala-library as a dependency of the p
roject
[ERROR] C:\temp\liftscala\src\main\scala
[INFO] Compiling 1 source files to C:\temp\liftscala\target\classes
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:3: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.{Global, Settings}
[WARNING]               ^
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:4: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.reporters.ConsoleReporter
[WARNING]               ^
[WARNING] two errors found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Best Regards
Niels

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: compile with mvn, using the compiler
Can you send me your pom?
I have an idea what the problem is, but I need your pom to check.  
I have done what your suggesting in the past without difficulty.

-Josh
On Dec 27, 2008, at 5:48 PM, "Niels Boldt" <nielsboldt [at] gmail [dot] com> wrote:

Hi

I'm trying to compile the following code using maven and the maven/scala plugin

package mine

 import scala.tools.nsc.{Global, Settings}
 import scala.tools.nsc.reporters.ConsoleReporter

etc ..

and I get the following error. The code compiles fine using scalac or using the eclipse plugin for scala. The problem is that it misses a reference to the scala-compiler.jar. I have tried adding it as a normal dependency in maven, eg something like

    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>2.7.2</version>
    </dependency>

where I have the jar installed on my local machine, however the plugin seems to ignore the dependency. Should I add dependencies in some special way when using scala/maven or should the compiler.jar be included automatically. I have grabbed the pom from the 'Lift' project



[INFO]    task-segment: [clean, compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\temp\liftscala\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:compile {execution: default}]
[WARNING] you don't define org.scala-lang:scala-library as a dependency of the p
roject
[ERROR] C:\temp\liftscala\src\main\scala
[INFO] Compiling 1 source files to C:\temp\liftscala\target\classes
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:3: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.{Global, Settings}
[WARNING]               ^
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:4: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.reporters.ConsoleReporter
[WARNING]               ^
[WARNING] two errors found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Best Regards
Niels

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk (nb [at] binaryconstructors [dot] dk" rel="nofollow">nb [at] binaryconstructors [dot] dk)
skype: nielsboldt
Niels Boldt
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Re: compile with mvn, using the compiler
Hi Josh

The file is attached.

Best Regards
Niels

On Sun, Dec 28, 2008 at 12:15 AM, Josh Suereth <joshua [dot] suereth [at] gmail [dot] com> wrote:
Can you send me your pom?
I have an idea what the problem is, but I need your pom to check.  
I have done what your suggesting in the past without difficulty.

-Josh
On Dec 27, 2008, at 5:48 PM, "Niels Boldt" <nielsboldt [at] gmail [dot] com> wrote:

Hi

I'm trying to compile the following code using maven and the maven/scala plugin

package mine

 import scala.tools.nsc.{Global, Settings}
 import scala.tools.nsc.reporters.ConsoleReporter

etc ..

and I get the following error. The code compiles fine using scalac or using the eclipse plugin for scala. The problem is that it misses a reference to the scala-compiler.jar. I have tried adding it as a normal dependency in maven, eg something like

    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>2.7.2</version>
    </dependency>

where I have the jar installed on my local machine, however the plugin seems to ignore the dependency. Should I add dependencies in some special way when using scala/maven or should the compiler.jar be included automatically. I have grabbed the pom from the 'Lift' project



[INFO]    task-segment: [clean, compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\temp\liftscala\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:compile {execution: default}]
[WARNING] you don't define org.scala-lang:scala-library as a dependency of the p
roject
[ERROR] C:\temp\liftscala\src\main\scala
[INFO] Compiling 1 source files to C:\temp\liftscala\target\classes
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:3: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.{Global, Settings}
[WARNING]               ^
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:4: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.reporters.ConsoleReporter
[WARNING]               ^
[WARNING] two errors found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Best Regards
Niels

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dknb [at] binaryconstructors [dot] dk
skype: nielsboldt



--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: compile with mvn, using the compiler
Niels, how familiar are you with the Maven pom?   I'm going to provide you with a better starter pom here.  I think one of the next things I should tackle is updating the scala-simple-archetype so people have better starting points for projects.

If you'd like to see an example of a multi-part-project using scala, the only one I have available is my "experimental" maven-scala-plugin:  http://github.com/jsuereth/maven-scala-plugin/tree/master
I'm working on trying to dogfood the plugin, so you'll see half of it is in java and the other part is in scala.  Anyway, the part in scala actually includes the scala-compiler as I'm trying to access the AST nodes directly to generate Maven-Mojo metadata.   The code is in pretty bad shape right now, but Hoepfully it'll be cleaned up over the next few days as i have some time to spend on it.

Anyway, here's the pom file fore you.  Let me know if this helps things start working.   Also, I personally use the q4e eclipse plugin to do maven dependency management.  I've heard of others using m2e successfully as well.  I'm not positive the eclipse:eclipse integration is totally ironed out, but you can copy what was in Lift's POM and get that working again.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.gmail.nielsboldt</groupId>
    <artifactId>my-sample-project</artifactId>
    <packaging>jar</packaging>
    <version>0.1-SNAPSHOT</version>
    <name>My Sample Project</name>
    <description>Sample Maven proejct that includes the scala compiler</description>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-compiler</artifactId>
            <version>2.7.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <pluginRepositories>
       <pluginRepository>
          <id>scala-tools.org</id>
          <name>Scala Tools Maven2 Repository</name>
          <url>http://scala-tools.org/repo-releases</url>
       </pluginRepository>
    </pluginRepositories>
    <repositories>
      <repository>
         <id>scala-tools.org</id>
         <name>Scala Tools Maven2 Repository</name>
         <url>http://scala-tools.org/repo-releases</url>
     </repository>
     <repository>
       <id>scala-tools.org.snapshots</id>
       <name>Scala Tools Maven2 Repository</name>
       <url>http://scala-tools.org/repo-snapshots</url>
       <snapshots/>
     </repository>
  </repositories>
</project>



On Sun, Dec 28, 2008 at 4:01 AM, Niels Boldt <nielsboldt [at] gmail [dot] com> wrote:
Hi Josh

The file is attached.

Best Regards
Niels

On Sun, Dec 28, 2008 at 12:15 AM, Josh Suereth <joshua [dot] suereth [at] gmail [dot] com> wrote:
Can you send me your pom?
I have an idea what the problem is, but I need your pom to check.  
I have done what your suggesting in the past without difficulty.

-Josh
On Dec 27, 2008, at 5:48 PM, "Niels Boldt" <nielsboldt [at] gmail [dot] com> wrote:

Hi

I'm trying to compile the following code using maven and the maven/scala plugin

package mine

 import scala.tools.nsc.{Global, Settings}
 import scala.tools.nsc.reporters.ConsoleReporter

etc ..

and I get the following error. The code compiles fine using scalac or using the eclipse plugin for scala. The problem is that it misses a reference to the scala-compiler.jar. I have tried adding it as a normal dependency in maven, eg something like

    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <version>2.7.2</version>
    </dependency>

where I have the jar installed on my local machine, however the plugin seems to ignore the dependency. Should I add dependencies in some special way when using scala/maven or should the compiler.jar be included automatically. I have grabbed the pom from the 'Lift' project



[INFO]    task-segment: [clean, compile]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\temp\liftscala\target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [scala:compile {execution: default}]
[WARNING] you don't define org.scala-lang:scala-library as a dependency of the p
roject
[ERROR] C:\temp\liftscala\src\main\scala
[INFO] Compiling 1 source files to C:\temp\liftscala\target\classes
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:3: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.{Global, Settings}
[WARNING]               ^
[WARNING] C:\temp\liftscala\src\main\scala\mine\MyClassCompiler.scala:4: error:
value tools is not a member of package scala
[WARNING]  import scala.tools.nsc.reporters.ConsoleReporter
[WARNING]               ^
[WARNING] two errors found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Best Regards
Niels

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dknb [at] binaryconstructors [dot] dk
skype: nielsboldt



--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland