将依赖项添加到jar类路径清单中

时间:2014-09-24 10:47:00

标签: java gradle dependencies classpath build.gradle

当我尝试向jar清单类路径添加依赖项时,它会抛出异常:

使用:

gradle 2.1

构建

apply plugin: 'java'

jar {
    manifest {
        attributes 'Implementation-Title': 'Main',
                   'Implementation-Version': version,
                   'Main-Class': 'com.apl.Main',
                   'Class-Path': configurations.compile.collect { it.getName() }.join(' ')
    }
}

repositories {
    flatDir {
        dirs 'libs','test_libs'
    }
}

dependencies {
    compile name: 'bcmail-jdk16-dss'
    compile name: 'bcprov-jdk16-dss'
    compile name: 'bctsp-jdk16-dss'
}

例外:

Caused by: org.gradle.api.InvalidUserDataException: You can't change configuration 'compile' because it is already resolved!

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

尝试放

dependencies { compile name: 'bcmail-jdk16-dss' compile name: 'bcprov-jdk16-dss' compile name: 'bctsp-jdk16-dss' }

之前

    jar {
    manifest {
        attributes 'Implementation-Title': 'Main',
                   'Implementation-Version': version,
                   'Main-Class': 'com.apl.Main',
                   'Class-Path': configurations.compile.collect { it.getName() }.join(' ')
    }
}