![](/img/trans.png)
[英]downgrading to Java 1.7 breaks com.google.common.collect usage
[英]Gradle 'error: package com.google.common.collect does not exist'
我正在關注一個小測試腳本並為其提供第一段代碼以使其變為綠色。 代碼是java,測試與java混在一起。 Java是Mac OSX“El Capitan”上的版本“1.8.0_60”。 gradle
是2.8版。
使用gradle build
,顯示的錯誤如下:
$ gradle build
:compileJava
/Users/rsalazar/exercism/java/etl/src/main/java/Etl.java:1: error: package com.google.common.collect does not exist
import com.google.common.collect.ImmutableMap;
^
/Users/rsalazar/exercism/java/etl/src/main/java/Etl.java:9: error: cannot find symbol
return ImmutableMap.of("a", 1);
^
symbol: variable ImmutableMap
location: class Etl
2 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.597 secs
這是build.gradle
文件:
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:4.10"
testCompile "org.easytesting:fest-assert-core:2.0M10"
testCompile "com.google.guava:guava:16+"
}
這是測試:( EtlTest.java
)
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.fest.assertions.api.Assertions.assertThat;
public class EtlTest {
private final Etl etl = new Etl();
@Test
public void testTransformOneValue() {
Map<Integer, List<String>> old = ImmutableMap.of(1, Arrays.asList("A"));
Map<String, Integer> expected = ImmutableMap.of("a", 1);
assertThat(etl.transform(old)).isEqualTo(expected);
}
}
這是測試中的代碼:( Etl.java
)
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class Etl {
public Map<String, Integer> transform(Map <Integer, List<String>> from) {
return ImmutableMap.of("a", 1);
}
}
我不是在尋求測試通過的幫助。 只是幫助用gradle編譯測試。 我很遺憾地說,在使用提供的錯誤消息進行編譯時我遇到了困難。 我在網上找不到任何幫助。 非常感謝!
由於您需要ImmutableMap
來編譯源代碼(不僅是測試源代碼),您還需要更改此行:
testCompile "com.google.guava:guava:16+"
對此:
compile "com.google.guava:guava:16+"
它將在編譯時為源代碼提供guava,從而解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.