Nếu bạn chỉ muốn kiểm tra mã Java từ Scala thì việc thiết lập dự án maven là khá dễ dàng. Vì tôi không phải là người dùng nhật thực, tôi không chắc nó hoạt động như thế nào với nhật thực. Tôi đã thử nghiệm với IntelliJ và nó hoạt động rất tốt. Không nên có bất kỳ vấn đề với nhật thực hoặc.
Tôi đã tạo đơn giản pom.xml
chỉ sử dụng trình biên dịch scala cho các thử nghiệm và sử dụng trình biên dịch java thông thường cho mã java chính.
pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow.Q13379591</groupId>
<artifactId>Q13379591</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.9.2</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.version}</artifactId>
<version>2.0.M4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-g:vars</arg>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0-M2</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
<stdout>W</stdout> <!-- Skip coloring output -->
</configuration>
<executions>
<execution>
<id>scala-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Bây giờ đây là một lớp Java đơn giản mà tôi muốn thử nghiệm:
src/main/java/com/stackoverflow/Hello.java
package com.stackoverflow;
/**
* @author maba, 2012-11-14
*/
public interface Hello {
String hello();
}
src/main/java/com/stackoverflow/HelloJava.java
package com.stackoverflow;
/**
* @author maba, 2012-11-14
*/
public class HelloJava implements Hello {
public String hello() {
return "Hello Java";
}
}
Và cuối cùng là lớp kiểm tra ScalaTest.
src/test/scala/com/stackoverflow/HelloJavaTest.scala
package com.stackoverflow
import org.scalatest.FlatSpec
/**
* @author maba, 2012-11-14
*/
class HelloJavaTest extends FlatSpec {
"HelloJava" should "be instance of Hello" in {
val hello = new HelloJava
val result = hello match {
case f:Hello => true
}
assert(result)
}
it should "say Hello Java" in {
val helloJava = new HelloJava
assert(helloJava.hello === "Hello Java")
}
}
Bây giờ bạn có thể chạy nó bằng lệnh này:
mvn test
Tôi nhấp chuột chỉ có thể phải vào trường hợp thử nghiệm trong IntelliJ và chạy thử nghiệm. Nó cũng có thể trong nhật thực.
Điều này có nghĩa là tôi cần chuyển đổi dự án java Eclipse của mình không? vui lòng xem câu hỏi chỉnh sửa. – user701254
Nếu bạn chỉ sử dụng trình biên dịch Scala mà không có maven, sau đó tham gia biên dịch nên làm việc trong nhật thực. –