0
私はbuild.gradleファイルに以下を追加しました。Gradleを使用して外部依存関係を持つjarを作成します
jar {
doFirst {
into('lib') {
from configurations.runtime
}
}}
「gradle build」を実行すると、すべての依存JARを含むJARファイルが作成されます。しかし、それはlibフォルダの依存するjarファイルを含むZIPファイルにJARを入れます。このZIPファイル構造は次のようになります。
-- 4.11-SNAPSHOT.jar
---- lib
----- lib/dependent1.jar
----- lib/dependent2.jar
-- lib
---- dependent1.jar
---- dependent2.jar
ZIPを生成したくありません。私は、生成されるすべての依存関係を含む単一のJARのみを必要とします。
-- 4.11-SNAPSHOT.jar
---- lib
----- lib/dependent1.jar
----- lib/dependent2.jar
完全build.gradleは以下の通りです:
repositories {
maven {
url 'https://repository.cloudera.com/content/repositories/releases/'
}
maven {
url 'https://repository.cloudera.com/content/repositories/third-party/'
}
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'com.company.projectname', name: 'domain', version: pppVersion
compile group: 'com.company.projectname', name: 'model', version: modelVersion
compile group: 'com.company.projectname', name: 'pipeline-util', version: pppVersion
compile group: 'com.cloudera.crunch', name: 'crunch', version: '0.3.0-3-cdh-5.2.1'
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.5.0-cdh5.3.3'
compile group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-common', version: '2.5.0-cdh5.3.3'
compile group: 'ch.hsr', name: 'geohash', version: '1.3.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
jar {
manifest {
attributes 'Main-Class': 'com.company.projectname.delta.DeltaClusterer'
}
classifier 'job'
doFirst {
into('lib') {
from configurations.runtime
}
}
}
親build.gradleが同様にあります。そして、次のようになります:
/**
* Dependencies for build script plugins. Project dependencies should
* be added further in this file.
*/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:2.2.0'
classpath 'org.hidetake:gradle-ssh-plugin:1.0.4'
classpath 'be.xvrt:release-plugin:0.5.1'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
// Release script for automated version management.
// Apply at root so it uses/updates the root gradle.properties file.
apply plugin: 'be.xvrt.release'
subprojects {
apply plugin: 'java' // Support for Java.
apply plugin: 'maven-publish' // Upload artifacts to Nexus.
apply plugin: 'be.xvrt.release' // Release script for automated version management.
apply plugin: 'org.hidetake.ssh' // Execute SSH commands.
apply plugin: 'rpm' // Builds RPM artifacts.
apply plugin: 'sonar-runner' // Creates Sonar reports.
apply plugin: 'project-report' // Creates a dependency report, very useful for finding dependency conflicts.
/**
* Global configuration.
*/
sourceCompatibility = 1.6
targetCompatibility = 1.6
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
/**
* Global dependency settings for all projects. Per project dependencies
* should be added to the build.gradle file in every project.
*/
// Common dependencies for all projects.
dependencies {
// Also see resolutionStrategy below when modifying semantic-TTOM-ddct version!
compile group: 'com.teleatlas.models', name: 'semantic-TTOM-ddct', version: '4.0.2.0'
compile group: 'com.google.guava', name: 'guava', version: '15.0'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile group: 'args4j', name: 'args4j', version: '2.0.29'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.8'
}
// The install artifact is only required for command line applications.
if (!tasks.findByPath('war')) {
task buildInstallZip(type: Zip) {
from jar.outputs.files
// Copy all dependencies into lib.
into('lib') {
from configurations.runtime.allArtifacts.files
from configurations.runtime
}
}
}
/**
* Publish to Nexus.
*/
artifacts {
archives buildSourcesJar
archives buildJavadocJar
if (!tasks.findByPath('war')) {
archives buildInstallZip
}
}
publishing {
publications {
maven(MavenPublication) {
if (tasks.findByPath('war')) {
from components.web
}
else {
from components.java
}
artifact buildSourcesJar {
classifier 'sources'
}
artifact buildJavadocJar {
classifier 'javadoc'
}
if (!tasks.findByPath('war')) {
artifact buildInstallZip {
classifier 'install'
}
}
}
}
}
}
/**
* Build RPM artifacts for command line applications.
*/
configure([project(':project1'),
project(':project2'),
project(':project3')]) {
task rpm(type: Rpm, dependsOn: 'jar') {
if (version.contains('SNAPSHOT')) {
logger.info('Building SNAPSHOT RPM.')
version project.version.replace('-SNAPSHOT', ".${System.currentTimeMillis()}")
}
else {
logger.info('Building RELEASE RPM.')
version project.version
release '1'
}
vendor 'company'
packageGroup 'company'
permissionGroup "Applications/${project.name}"
arch NOARCH
os LINUX
into '/usr/share/java/'
from(jar.outputs.files) {
into project.name
}
from(configurations.runtime) {
into "${project.name}/lib"
}
}
// When publishing artifacts, the rpm is also published (and created).
publish.dependsOn publishRpm
publishRpm.dependsOn rpm
}
これは何が行われる必要がありますか?
'build.gradle'スクリプト全体または少なくとも関連する部分を投稿してください。他のgradleプラグインが適用されているようです。 – Opal
@Opal、プロジェクトのbuild.gradleと親build.gradleで質問を編集しました。チェックしてください。ありがとう。 – Yogesh
私はfatjarまたはshadowJarプラグインを利用できると思います。例:https://github.com/musketyr/gradle-fatjar-plugin – gaganbm