2017-02-22 31 views
1

我想從gradle構建文件中調用一個定製的groovy插件。但是我在解決ssh的類時遇到了錯誤。下面是構建文件,定製groovy插件和錯誤的一部分。無法解析gradle.build中的ssh類

的build.gradle

plugins { 
    id 'org.sonarqube' version '2.0.1' 
    id 'groovy' 
    id 'org.hidetake.ssh' version'2.7.0' 
} 

dependencies { 
    compile gradleApi() 
    compile localGroovy() 
} 

CustPlugin.groovy

package com.nielsen.gradle 

import org.slf4j.Logger 
import org.slf4j.LoggerFactory 

import java.text.SimpleDateFormat 

import org.gradle.api.Project 
import org.gradle.api.Plugin 
import org.gradle.api.GradleException 
import org.gradle.api.plugins.BasePlugin 
import org.gradle.api.tasks.bundling.Zip 

import org.hidetake.groovy.ssh.Ssh.* 
import org.hidetake.groovy.ssh.core.Service 

import com.nielsen.gradle.cmRegistry.CMRegistryPlugin 

錯誤

C:\Users\528302\Documents\gradle_all\projectf1>gradle build 
:compileJava UP-TO-DATE 
:compileGroovy 
startup failed: 
C:\Users\528302\Documents\gradle_all\projectf1\src\main\groovy\com\nielsen\gradle\CustPlugin.groovy: 14: unable to resolve class org.hidetake.groovy.ssh.Ssh 
@ line 14, column 1. 
    import org.hidetake.groovy.ssh.Ssh 
^

C:\Users\528302\Documents\gradle_all\projectf1\src\main\groovy\com\nielsen\gradle\CustPlugin.groovy: 15: unable to resolve class org.hidetake.groovy.ssh.core.Service 

@ line 15, column 1. 
    import org.hidetake.groovy.ssh.core.Service 
^

C:\Users\528302\Documents\gradle_all\projectf1\src\main\groovy\com\nielsen\gradle\CustPlugin.groovy: 17: unable to resolve class com.nielsen.gradle.cmRegistry.CMRegi 
stryPlugin 
@ line 17, column 1. 
    import com.nielsen.gradle.cmRegistry.CMRegistryPlugin 
^

請幫助解決這個...謝謝。

回答

1

你在混合兩件事。通過使用plugins { }閉包,您將爲buildscript本身添加依賴關係。但在這種情況下,您正在構建的代碼依賴於某個庫,而不是構建腳本。

嘗試添加以下內容dependencies { }

compile group: 'org.hidetake', name: 'groovy-ssh', version: '2.8.0'

,所以你最終不得不

plugins { 
    id 'org.sonarqube' version '2.0.1' 
    id 'groovy' 
    id 'org.hidetake.ssh' version'2.7.0' 
} 

dependencies { 
    compile gradleApi() 
    compile localGroovy() 
    compile group: 'org.hidetake', name: 'groovy-ssh', version: '2.8.0' 
} 
+0

感謝馬丁......我試過,但我得到了follwoing錯誤: *什麼出錯了: 無法解析配置':compileClasspath'的所有依賴關係。 >無法解析外部依賴關係org.hidetake:groovy-ssh:1.1.6,因爲沒有定義存儲庫。 必需: 項目: – ghost0806

+0

相同的版本2.8.0 – ghost0806

+0

現在你缺少存儲庫聲明。 添加 '{庫 mavenCentral() }' 你'build.gradle' –

相關問題