2017-03-02 102 views
1

我有一個使用json.jar庫的簡單java項目。 gradle.build文件內容是:配置':compile'在解析後無法更改依賴關係

apply plugin: 'java' 
jar { 
    manifest { 
    attributes(
     'Class-Path': configurations.compile.collect { it.getName() }.join(' '), 
     'Main-Class': 'main.java.Main' 
    ) 
    } 
} 
dependencies { 
    compile 'org.json:json:20160212' 
} 

問題是,當我想JSON添加到我的類路徑中,並使用它,這個錯誤發生

* Where: 
Build file '/home/tina-admin/Documents/myJavaProjects/LongMan/build.gradle' line: 11 

* What went wrong: 
A problem occurred evaluating root project 'LongMan'. 
> Cannot change dependencies of configuration ':compile' after it has been resolved. 

我怎樣才能解決這個問題?

回答

2

首先,你通常dependencies {...}前添加repositories塊到指定的依賴是從(被檢索。

repositories { 
    mavenCentral() 
} 

然後,如果你jar塊似乎工作之前把dependencies塊,雖然我不確定爲什麼它不能以其他方式工作(也許jar {...}使用compile配置並「鎖定」它)。

+0

tnx很好運行 – reza

+2

附加組件:問題似乎是由使用'confi gutries.compile'在'jar'塊中 – rrobby86

相關問題