Reputation: 335
I would like to pack my whole application into one .jar file using gradle. But it seems to not working.
Here's my build.gradle file:
group 'imgscrapper'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'java-library-distribution'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
jar {
manifest {
sourceSets.main.java.srcDirs = ['Main/src']
attributes 'Main-Class': 'imgscrapper.Main'
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.jsoup:jsoup:1.9.2'
compile 'com.intellij:forms_rt:7.0.3'
}
and catalog tree:
.
├── production
│ └── Main
│ ├── com
│ │ └── intellij
│ │ └── uiDesigner
│ │ └── core
│ │ ├── AbstractLayout.class
│ │ ├── DimensionInfo.class
│ │ ├── GridConstraints.class
│ │ ├── GridLayoutManager.class
│ │ ├── HorizontalInfo.class
│ │ ├── LayoutState.class
│ │ ├── Spacer.class
│ │ ├── SupportCode.class
│ │ ├── SupportCode$TextWithMnemonic.class
│ │ ├── Util.class
│ │ └── VerticalInfo.class
│ └── imgscrapper
│ ├── Frame$1.class
│ ├── Frame$2.class
│ ├── Frame$3.class
│ ├── Frame$4.class
│ ├── Frame$5.class
│ ├── Frame.class
│ ├── GetImages.class
│ └── Main.class
└── test
└── Main
└── com
└── intellij
└── uiDesigner
└── core
├── AbstractLayout.class
├── DimensionInfo.class
├── GridConstraints.class
├── GridLayoutManager.class
├── HorizontalInfo.class
├── LayoutState.class
├── Spacer.class
├── SupportCode.class
├── SupportCode$TextWithMnemonic.class
├── Util.class
└── VerticalInfo.class
As far I know gradle should import jsoup into package on his own however when I'm trying to run my jar file I get:
java.lang.NoClassDefFoundError: org/jsoup/nodes/Document
What am I doing wrong ?
Upvotes: 1
Views: 775
Reputation: 84854
No, this is not how it works. Dependencies will not be added to the jar file being built out-of-the box.
To fix it you need to either build a fat-jar (with this plugin) or use application plugin (delivered by gradle with the distribution).
Upvotes: 1