Gradle build dependancy throwing ClassNotFoundException

妖精的绣舞 提交于 2019-12-05 19:31:17

After some research I have used the following build script to build my Jar successfully.

apply plugin: 'java'
apply plugin: 'eclipse'

defaultTasks 'clean', 'build'

repositories {
    mavenCentral()
}

jar {
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest {
        attributes 'Implementation-Title': 'ndeploy',
            'Implementation-Version': '0.1.0',
            'Built-By': System.getProperty('user.name'),
            'Built-Date': new Date(),
            'Built-JDK': System.getProperty('java.version'),
            'Main-Class': 'com.Main'
    }
}

dependencies {
    compile 'org.apache.httpcomponents:fluent-hc:4.3.3'
    compile 'org.apache.httpcomponents:httpclient-cache:4.3.3'
    compile 'org.apache.httpcomponents:httpcore:4.1'
    compile 'org.apache.httpcomponents:httpmime:4.3.3'
    compile 'org.apache.httpcomponents:httpclient:4.3.3'
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-all:1.9.5'
}

buildscript {
    dependencies {
        classpath fileTree(dir: '../../build/libs', include: '*.jar', excludes: ['*javadoc.jar', '*sources.jar'])
    }
}

Comments appreciated

Since the runtime configuration also contains the compile configuration, then you can exclude a snippet of code which collecting compile config from the example above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!