2016-08-18 55 views
1

我有一個編譯本地jar(A)的項目(B)。我需要排除jar(A)中的依賴關係,但構建jar時無法執行此操作。我可以建立我怎麼過想罐子,但我必須有它的依賴性,只有排除這些項目B.無法排除jar中的依賴關係

這是的build.gradle項目A的罐子:

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'application' 

repositories { 
    mavenCentral() 
} 

jar { 
    baseName = 'test' 
    version = '0.1.0' 

    manifest { 
     attributes ("Main-Class": "Main") 
    } 
} 

dependencies { 
    compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE") // I need this excluded later 
    compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE") // I need this excluded later 
    /* 
    some other dependencies here 
    */ 
} 

這是的build.gradle項目B:

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'application' 

repositories { 
    mavenCentral() 
    flatDir(dirs: "lib") 
} 

sourceCompatibility = 1.8 

dependencies { 
    compile ':test:0.1.0' // this is the jar I need to exclude some things from 

    compile("org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE") 
    compile("org.springframework.boot:spring-boot-starter-jetty:1.4.0.RELEASE") 
} 

這似乎是使用普通的排除條款不起作用

compile (':test:0.1.0') { 
    exclude group: 'org.springframework.boot' // doesn't work 
} 

任何幫助將不勝感激。

+0

該語法應該工作 - dependencyInsight說什麼? –

+0

正在運行'dependencyInsight --configuration compile --dependency test'' 產生':dependencyInsight:test:0.1.0 \ --- compile' –

+0

噢,我的意思是在它上面運行它。 '衝刺引導起動web'。 –

回答

0

我從here得到了我的答案。顯然,從文件存儲庫中讀取group等屬性是不可能的。我最終將我的依賴關係發佈到私有存儲庫(tutorial),並從那裏導入)

+0

Ya也會工作。創建一個私人回購並上傳它,並在build.gradle中的存儲庫部分添加url。 –

+0

你能告訴我,爲什麼fileTree不工作?哪裏出錯了?你有什麼錯誤? –

+0

沒有錯誤。 '排除'條款沒有做任何事情。不管我試圖排除什麼。這是幾天前,所以要真實我不能說,如果這是因爲我在打包jar的時候犯了一個錯誤,或者你不能從'filetree'中排除 –

0

我明白了你的意思,基於組的排除不會與flatDir回購協議一起使用,因爲平面目錄沒有組信息 因此,最好在libs文件夾ProjectB中包含'test:0.1.0'jar,而不是將其添加到flatDir repo 因此,通過使用fileTree,我們可以獲得ProjectB的依賴項ProjectA(test:0.1.0 jar)。 從文件樹,我們可以排除排除罐(A)內的依賴性 請通過下面的代碼:

compile fileTree(dir: '../webserver/lib', include: '*.jar') 

在這裏,我們將包含../webserver/lib中的所有jar作爲依賴關係。

只需在fileTree上使用排除。語法與include相同。

這應該工作。

+0

謝謝。我從'fileTree'開始,轉到'flatDir',因爲它不起作用,但我可能只是犯了一個錯誤。但我認爲,指出如果'jar'是一個FatJar,那麼這也不起作用。 –