2012-10-10 18 views
7

के साथ प्रारंभ करना मैं निम्नलिखित के साथ एक नई स्केला प्रोजेक्ट बनाया:स्काला, Scalatest, और Maven

mvn org.apache.maven.plugins:maven-archetype-plugin:2.2:generate 
    -DarchetypeGroupId=org.scala-tools.archetypes 
    -DarchetypeArtifactId=scala-archetype-simple 
    -DarchetypeVersion=1.3 
    -DgroupId=myGroup 
    -DartifactId=myProject 
    -Dversion=0.1.0 
    -DinteractiveMode=false 

कौन मेरा पीछा पोम देता है:

<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>myGroup</groupId> 
    <artifactId>myProject</artifactId> 
    <version>0.1.0</version> 
    <name>${project.artifactId}</name> 
    <description>My wonderfull scala app</description> 
    <inceptionYear>2010</inceptionYear> 
    <licenses> 
    <license> 
     <name>My License</name> 
     <url>http://....</url> 
     <distribution>repo</distribution> 
    </license> 
    </licenses> 

    <properties> 
    <maven.compiler.source>1.5</maven.compiler.source> 
    <maven.compiler.target>1.5</maven.compiler.target> 
    <encoding>UTF-8</encoding> 
    <scala.version>2.8.0</scala.version> 
    </properties> 

<!-- 
    <repositories> 
    <repository> 
     <id>scala-tools.org</id> 
     <name>Scala-Tools Maven2 Repository</name> 
     <url>http://scala-tools.org/repo-releases</url> 
    </repository> 
    </repositories> 

    <pluginRepositories> 
    <pluginRepository> 
     <id>scala-tools.org</id> 
     <name>Scala-Tools Maven2 Repository</name> 
     <url>http://scala-tools.org/repo-releases</url> 
    </pluginRepository> 
    </pluginRepositories> 
--> 
    <dependencies> 
    <dependency> 
     <groupId>org.scala-lang</groupId> 
     <artifactId>scala-library</artifactId> 
     <version>${scala.version}</version> 
    </dependency> 

    <!-- Test --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.scala-tools.testing</groupId> 
     <artifactId>specs_${scala.version}</artifactId> 
     <version>1.6.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.scalatest</groupId> 
     <artifactId>scalatest</artifactId> 
     <version>1.2</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <sourceDirectory>src/main/scala</sourceDirectory> 
    <testSourceDirectory>src/test/scala</testSourceDirectory> 
    <plugins> 
     <plugin> 
     <groupId>org.scala-tools</groupId> 
     <artifactId>maven-scala-plugin</artifactId> 
     <version>2.15.0</version> 
     <executions> 
      <execution> 
      <goals> 
       <goal>compile</goal> 
       <goal>testCompile</goal> 
      </goals> 
      <configuration> 
       <args> 
       <arg>-make:transitive</arg> 
       <arg>-dependencyfile</arg> 
       <arg>${project.build.directory}/.scala_dependencies</arg> 
       </args> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.6</version> 
     <configuration> 
      <useFile>false</useFile> 
      <disableXmlReport>true</disableXmlReport> 
      <!-- If you have classpath issue like NoDefClassError,... --> 
      <!-- useManifestOnlyJar>false</useManifestOnlyJar --> 
      <includes> 
      <include>**/*Test.*</include> 
      <include>**/*Suite.*</include> 
      </includes> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

मैं mvn test और नमूना चला सकते हैं परीक्षण सफलतापूर्वक चलाते हैं। मैं स्कैला के नवीनतम संस्करण का उपयोग करना चाहता हूं (मैंने डाउनलोड/स्थापित 2.9.2 ...), लेकिन most recent version of the org.scala-tools.testing scala_VERSION dependency seems to be 2.9.1। मैं अपने पोम में निम्न परिवर्तन किए:

<scala.version>2.9.1</scala.version> 

और

<dependency> 
     <groupId>org.scala-tools.testing</groupId> 
     <artifactId>specs_${scala.version}</artifactId> 
     <version>1.6.5</version> 
     <scope>test</scope> 
    </dependency> 
अब

,

------------------------------------------------------- 
    T E S T S 
------------------------------------------------------- 
Running samples.ListSuite 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.674 sec <<< FAILURE! 
initializationError(samples.ListSuite) Time elapsed: 0.003 sec <<< ERROR! 
java.lang.ClassCastException: scala.collection.immutable.Set$EmptySet$ cannot be 
    cast to scala.collection.generic.Addable 
     at org.scalatest.FunSuite$class.test(FunSuite.scala:1039) 
     at samples.ListSuite.test(scalatest.scala:59) 
     at samples.ListSuite.<init>(scalatest.scala:61) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:525) 
     at java.lang.Class.newInstance0(Class.java:372) 
     at java.lang.Class.newInstance(Class.java:325) 
     at org.scalatest.junit.JUnitRunner.<init>(JUnitRunner.scala:62) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 

     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:525) 
     at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31) 
     at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24) 
     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 
     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29) 
     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57) 
     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24) 
     at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:51) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103) 
     at org.apache.maven.surefire.Surefire.run(Surefire.java:169) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:601) 
     at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) 
     at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021) 

Running samples.StackSuite 
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.12 sec 
Running samples.AppTest 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec 

Results : 

Tests in error: 
    initializationError(samples.ListSuite) 

Tests run: 4, Failures: 0, Errors: 1, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 6.880s 
[INFO] Finished at: Wed Oct 10 01:10:56 ADT 2012 
[INFO] Final Memory: 9M/112M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.6:test (default-test) on project myProject: There are test failures. 
[ERROR] 
[ERROR] Please refer to C:\Dropbox\work\dev\scalasandbox\target\surefire-reports for the individual test results. 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

देता चल mvn test मैं शायद सबसे सरल संभव द्वारा बनाई परीक्षण (नमूने में से कुछ है मेवेन आर्केटाइप प्लगइन), और एक मामूली संस्करण द्वारा स्कैला बंपिंग उन्हें तोड़ रहा है? क्या मुझे सिर्फ स्काला 2.8 के साथ रहना चाहिए जब तक कि मैवेन टूल्स पकड़ न जाए?

+1

आप परीक्षण चलाने से पहले साफ किया? यह एक बाइनरी असंगतता की तरह दिखता है। –

+0

हां; 'एमवीएन क्लीन' मदद नहीं की। – MrDrews

उत्तर

13

आपका आर्टिफैक्ट पुराना है।

स्कैला का नवीनतम संस्करण 2.10 है। वर्तमान में स्कालाटेस्ट को विभिन्न गठबंधन के तहत वितरित किया जा रहा है और यह स्कैला के नवीनतम संस्करण का समर्थन करता है। यहाँ निर्भरता है:

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>scala-maven-plugin</artifactId> 
    <version>3.1.0</version> 
    <executions> 
     <execution> 
     <phase>compile</phase> 
     <goals> 
      <goal>compile</goal> 
      <goal>testCompile</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

आप के बाद से उन सभी कलाकृतियों केंद्रीय रेपो के साथ वितरित किया जा रहा है, किसी भी खजाने निर्दिष्ट करने की आवश्यकता नहीं है:

<dependency> 
    <groupId>org.scalatest</groupId> 
    <artifactId>scalatest_2.10</artifactId> 
    <version>2.0.M5b</version> 
    <scope>test</scope> 
</dependency> 

तुम भी एक अलग प्लगइन की आवश्यकता होगी।

Here's an example of a complete pom of a project depending on the Scala 2.10

+0

मेवेन-आर्केटाइप-प्लगइन द्वारा उत्पन्न परीक्षण 2.10.0-एम 7 के साथ 'mvn संकलन' नहीं करेंगे। मुझे लगता है कि जवाब "मेवेन-आर्केटाइप-प्लगइन का उपयोग न करें"। स्कैला (टूल्स/libs) में पीछे की संगतता की सामान्य कमी है, जो मुझे निराशाजनक लगता है। – MrDrews

+0

दाएं। कोई भी archetype का उपयोग करता है। स्पष्ट रूप से मुझे आर्केटाइप पीढ़ी मेवेन की एक अनावश्यक और भ्रमित विशेषता मिलती है। –

+0

मैंने आपके सॉर्म प्रोजेक्ट को क्लोन किया, लेकिन यह संकलित नहीं होगा (मुझे आपकी sext निर्भरता याद आ रही है)। मुझे लगता है कि मैं अभी 2.8 के साथ रहूंगा - मैं स्कैला पुस्तक में प्रोग्रामिंग के माध्यम से काम कर रहा हूं जो 2.8 के लिए लिखा गया था, वैसे भी। – MrDrews

3

उपयोग specs_2.9.1:1.6.9

और latest version of plugin

<groupId>net.alchim31.maven</groupId> 
<artifactId>scala-maven-plugin</artifactId> 
<version>3.2.2</version> 

Old scala maven plugin in not longer supported.

+0

धन्यवाद, लेकिन मुझे नए स्काला-मैवेन-प्लगइन के साथ एक ही क्लासकास्ट अपवाद प्राप्त हो रहा है।कम से कम मैं त्रुटियों के बिना 'mvn संकलन' कर सकते हैं, हालांकि: एस – MrDrews