Hi,
I would like to use scala scripts inside of Maven, so I've embedded a short Scala script like described here: http://www.sonatype.com/books/mcookbook/reference/sect-scala-script-inline.html
I got following error:
System Environment Details:
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_16
Java home: C:\Programme\Java\jdk1.6.0_16\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "x86" Family: "windows"
POM:
<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>org.sonatype.mcookbook</groupId>
<artifactId>scala-script</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>scala-script</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.scalaforge</groupId>
<artifactId>scalax</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>script</goal>
</goals>
<configuration>
<keepGeneratedScript>true</keepGeneratedScript>
<script>
<![CDATA[
import java.io.{File, PrintWriter, FileWriter};
import scalax.io.FileExtras;
import scala.collection.mutable.HashSet;
val outputDir = project.getBuild().getOutputDirectory();
val depsFile = new FileExtras( new File( outputDir, "deps.txt" ) )
val pw = depsFile.printWriter
val depSet = new HashSet[String]
for( d <- project.getDependencies() ) {
depSet += d.getGroupId + ":" + d.getArtifactId + ":" + d.getVersion
}
pw.writeLines( depSet.toSeq )
]]>
</script>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>scala-tools</id>
<url>http://scala-tools.org/repo-releases/</url>
</repository>
</repositories>
</project>
Call:
mvn package
Stacktrace:
C:\Develop\TEST\scala-test>mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building scala-script
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Develop\TEST\scala-test\src\main\resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to C:\Develop\TEST\scala-test\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Develop\TEST\scala-test\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to C:\Develop\TEST\scala-test\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\Develop\TEST\scala-test\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running jar.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.03 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [scala:script {execution: default}]
[INFO] Checking for multiple versions of scala
C:\Develop\TEST\scala-test\target\.scalaScriptGen\embeddedScript_1.scala:5: error: not found: value project
val outputDir = project.getBuild().getOutputDirectory();
^
C:\Develop\TEST\scala-test\target\.scalaScriptGen\embeddedScript_1.scala:3: error: not found: value scalax
import scalax.io.FileExtras;
^
C:\Develop\TEST\scala-test\target\.scalaScriptGen\embeddedScript_1.scala:9: error: not found: value project
for( d <- project.getDependencies() ) {
^
three errors found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1(Exit value: 1)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 32 seconds
[INFO] Finished at: Fri Apr 15 17:31:39 CEST 2011
[INFO] Final Memory: 27M/49M
[INFO] ------------------------------------------------------------------------
C:\Develop\TEST\scala-test>
The content of C:\Develop\TEST\scala-test\target.scalaScriptGen\embeddedScript_1.scala:
class embeddedScript_1 {
import java.io.{File, PrintWriter, FileWriter};
import scalax.io.FileExtras;
import scala.collection.mutable.HashSet;
val outputDir = project.getBuild().getOutputDirectory();
val depsFile = new FileExtras( new File( outputDir, "deps.txt" ) )
val pw = depsFile.printWriter
val depSet = new HashSet[String]
for( d <- project.getDependencies() ) {
depSet += d.getGroupId + ":" + d.getArtifactId + ":" + d.getVersion
}
pw.writeLines( depSet.toSeq )
}
Compare the generated sources! The Maven Credentials (like "project:org.scala_tools.maven.model.MavenProjectAdapter,log:org
.apache.maven.plugin.logging.Log") are missing!
Should be (see http://www.sonatype.com/books/mcookbook/reference/sect-scala-script-inline.html):
import scala.collection.jcl.Conversions._
class embeddedScript_1(project:org.scala_tools.maven.model.MavenProjectAdapter,log:org
.apache.maven.plugin.logging.Log) {
import java.io.{File, PrintWriter, FileWriter};
import scalax.io.FileExtras;
import scala.collection.mutable.HashSet;
val outputDir = project.getBuild().getOutputDirectory();
val depsFile = new FileExtras( new File( outputDir, "deps.txt" ) )
val pw = depsFile.printWriter
val depSet = new HashSet[String]
for( d <- project.getDependencies() ) {
depSet += d.getGroupId + ":" + d.getArtifactId + ":" + d.getVersion
}
pw.writeLines( depSet.toSeq )
}
Running maven with -X option returned classpath as follows:
[C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-i18n\1.0-beta-6\plexus-i18n-1.0-beta-6.jar
C:\Users\Administrator\.m2\repository\velocity\velocity-dep\1.4\velocity-dep-1.4.jar
C:\Users\Administrator\.m2\repository\com\jcraft\jsch\0.1.23\jsch-0.1.23.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\shared\maven-dependency-tree\1.2\maven-dependency-tree-1.2.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-interactivity-api\1.0-alpha-4\plexus-interactivity-api-1.0-alpha-4.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-model\2.0.9\maven-model-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact\2.0\maven-artifact-2.0.jar
C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact\2.0.9\maven-artifact-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-container-default\1.0-alpha-9-stable-1\plexus-container-default-1.0-alpha-9-stable-1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-site-renderer\1.0-alpha-7\doxia-site-renderer-1.0-alpha-7.jar
C:\Users\Administrator\.m2\repository\commons-beanutils\commons-beanutils\1.6\commons-beanutils-1.6.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-model\2.0\maven-model-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\wagon\wagon-provider-api\1.0-beta-2\wagon-provider-api-1.0-beta-2.jar
C:\Users\Administrator\.m2\repository\org\scalaforge\scalax\0.1\scalax-0.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-project\2.0.5\maven-project-2.0.5.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-profile\2.0\maven-profile-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact-manager\2.0\maven-artifact-manager-2.0.jar
C:\Users\Administrator\.m2\repository\commons-validator\commons-validator\1.2.0\commons-validator-1.2.0.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-utils\1.5.1\plexus-utils-1.5.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\wagon\wagon-http-lightweight\1.0-alpha-5\wagon-http-lightweight-1.0-alpha-5.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-parameter-documenter\2.0\maven-plugin-parameter-documenter-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\wagon\wagon-provider-api\1.0-alpha-5\wagon-provider-api-1.0-alpha-5.jar
C:\Users\Administrator\.m2\repository\commons-cli\commons-cli\1.0\commons-cli-1.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-settings\2.0\maven-settings-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-error-diagnostics\2.0\maven-error-diagnostics-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-core\1.0-alpha-8\doxia-core-1.0-alpha-8.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-model\2.0.5\maven-model-2.0.5.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\shared\maven-dependency-analyzer\1.1\maven-dependency-analyzer-1.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-sink-api\1.0-alpha-7\doxia-sink-api-1.0-alpha-7.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-velocity\1.1.3\plexus-velocity-1.1.3.jar
C:\Users\Administrator\.m2\repository\org\scala-lang\scala-compiler\2.7.3\scala-compiler-2.7.3.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-utils\1.5.15\plexus-utils-1.5.15.jar
C:\Users\Administrator\.m2\repository\commons-beanutils\commons-beanutils\1.7.0\commons-beanutils-1.7.0.jar
C:\Users\Administrator\.m2\repository\org\scala-tools\maven-scala-plugin\2.10.1\maven-scala-plugin-2.10.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-repository-metadata\2.0.9\maven-repository-metadata-2.0.9.jar
C:\Users\Administrator\.m2\repository\commons-lang\commons-lang\1.0\commons-lang-1.0.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-utils\1.4.2\plexus-utils-1.4.2.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-project\2.0.4\maven-project-2.0.4.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-container-default\1.0-alpha-9\plexus-container-default-1.0-alpha-9.jar
C:\Users\Administrator\.m2\repository\jline\jline\0.9.93\jline-0.9.93.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\reporting\maven-reporting-impl\2.0.4\maven-reporting-impl-2.0.4.jar
C:\Users\Administrator\.m2\repository\commons-collections\commons-collections\2.1\commons-collections-2.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-decoration-model\1.0-alpha-8\doxia-decoration-model-1.0-alpha-8.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\wagon\wagon-ssh\1.0-alpha-5\wagon-ssh-1.0-alpha-5.jar
C:\Users\Administrator\.m2\repository\xml-apis\xml-apis\2.0.2\xml-apis-2.0.2.jar
C:\Users\Administrator\.m2\repository\oro\oro\2.0.8\oro-2.0.8.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-registry\2.0\maven-plugin-registry-2.0.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-utils\1.2\plexus-utils-1.2.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-container-default\1.0-alpha-8\plexus-container-default-1.0-alpha-8.jar
C:\Users\Administrator\.m2\repository\asm\asm\3.0\asm-3.0.jar
C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-api\1.5.0\slf4j-api-1.5.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\wagon\wagon-file\1.0-alpha-5\wagon-file-1.0-alpha-5.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-registry\2.0.9\maven-plugin-registry-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-api\2.0.9\maven-plugin-api-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-project\2.0\maven-project-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\shared\maven-common-artifact-filters\1.0\maven-common-artifact-filters-1.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-descriptor\2.0\maven-plugin-descriptor-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact\2.0.8\maven-artifact-2.0.8.jar
C:\Users\Administrator\.m2\repository\commons-collections\commons-collections\2.0\commons-collections-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\reporting\maven-reporting-api\2.0\maven-reporting-api-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-api\2.0\maven-plugin-api-2.0.jar
C:\Users\Administrator\.m2\repository\commons-logging\commons-logging\1.0.3\commons-logging-1.0.3.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-archiver\1.0-alpha-7\plexus-archiver-1.0-alpha-7.jar
C:\Users\Administrator\.m2\repository\org\scala-lang\scala-library\2.7.3\scala-library-2.7.3.jar
C:\Develop\TEST\scala-test\target\classes/
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-core\1.0-alpha-7\doxia-core-1.0-alpha-7.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-repository-metadata\2.0\maven-repository-metadata-2.0.jar
C:\Users\Administrator\.m2\repository\oro\oro\2.0.7\oro-2.0.7.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-settings\2.0.9\maven-settings-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-profile\2.0.9\maven-profile-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-plugin-api\2.0.4\maven-plugin-api-2.0.4.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-model\2.2.0\maven-model-2.2.0.jar
C:\Users\Administrator\.m2\repository\velocity\velocity\1.4\velocity-1.4.jar
C:\Users\Administrator\.m2\repository\classworlds\classworlds\1.1-alpha-2\classworlds-1.1-alpha-2.jar
C:\Users\Administrator\.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-container-default\1.0-alpha-7\plexus-container-default-1.0-alpha-7.jar
C:\Users\Administrator\.m2\repository\xml-apis\xml-apis\1.0.b2\xml-apis-1.0.b2.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-monitor\2.0\maven-monitor-2.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-project\2.0.8\maven-project-2.0.8.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\doxia\doxia-site-renderer\1.0-alpha-8\doxia-site-renderer-1.0-alpha-8.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-core\2.0\maven-core-2.0.jar
C:\Users\Administrator\.m2\repository\org\codehaus\plexus\plexus-utils\1.0.4\plexus-utils-1.0.4.jar
C:\Users\Administrator\.m2\repository\commons-logging\commons-logging\1.0\commons-logging-1.0.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\shared\maven-plugin-testing-harness\1.1\maven-plugin-testing-harness-1.1.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact-manager\2.0.9\maven-artifact-manager-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-project\2.0.9\maven-project-2.0.9.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\maven-artifact\2.0.5\maven-artifact-2.0.5.jar
C:\Users\Administrator\.m2\repository\org\apache\maven\reporting\maven-reporting-api\2.0.4\maven-reporting-api-2.0.4.jar
C:\Users\Administrator\.m2\repository\plexus\plexus-utils\1.0.2\plexus-utils-1.0.2.jar
C:\Users\Administrator\.m2\repository\commons-digester\commons-digester\1.6\commons-digester-1.6.jar]
Scalax Library and other ones are listed so I don't understand this issue.
Can anybody help me?
thx in advance
golbie