Gradle does nothing on distZip task from distribution plugin - gradle

I have a Problem with the distribution Plugin of Gradle. I just want to use the plugin to bundle all my files together (jar's, shell-scripts, ...).
Here my build.gradle:
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'distribution'
sourceCompatibility = 1.7
targetCompatibility = 1.7
publishing {
...
}
repositories {
mavenCentral()
}
dependencies {
// public libraries
compile group: 'javax', name: 'javaee-api', version: '7.0'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.2'
compile group: 'commons-cli', name: 'commons-cli', version: '1.2'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'org.apache.axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.4'
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.10'
runtime group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
// this is a dirty workaround
// because I don't have deploy rights on artifactory and nobody has time for deploying my artifacts
compile fileTree(dir: 'lib', include: '*.jar')
}
Here the output:
$ ./gradlew distTar
Defaulting memory setting '-Xmx1024M'...
:distZip UP-TO-DATE
BUILD SUCCESSFUL
Total time: 2.44 secs
And nothing happens. No Zip File is created.
I'm using the latest version of Gradle (2.2.1)
Important for me is also, that I can use the installDist option of the plugin.
Any Ideas what's going wrong?

I found out what the Problem was:
The distZip wasn't working, because there were no files or libraries configured to be packed into the archive. By default, only the src/$distribution.name/dist is considered. The rest must be specified.
To ensure that at least the jar-File of the project is contained too, I used the plugin "java-library-distribution" instead of "distribution"
Furthermore I specified more files to consider:
distributions {
main {
contents {
from { 'distrib' }
}
}
}

If your $buildDir is empty, you have to configure a distribution:
distributions {
main {
baseName = 'someName'
contents {
from { 'src/readme' }
}
}
}
Also see https://gradle.org/docs/current/userguide/distribution_plugin.html

Related

With the new update of JDA 4.2.0 the new built JAR file on the VPS returns NoClassDefFoundError

With the new update of JDA 4.2.0 trying to run the jar file on the VPS fails.
I have tried various options, such as
creating a fat jar
searching for other similar issues
source 1
source 2
Yet none of these options seemed to work, since the VPS console output stays unchanged:
Error: Could not find or load main class ...
Caused by: java.lang.NoClassDefFoundError: net/dv8tion/jda/api/hooks/ListenerAdapter
So my current question is, what should my gradle.build look like, or is this a problem of the VPS not refreshing correctly? Or perhaps another problem I'm not aware of.
As for what my gradle.build looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
group '...'
version '2.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter(
)
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_168'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
jar {
manifest {
attributes(
'Main-Class': '...'
)
}
}
NOTE: In the previous snapshot of 1.0-SNAPSHOT this following gradle.build worked to start up the project:
plugins {
id 'java'
id 'application'
}
group '...'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:3.5.0_329'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
You can use this build.gradle to build a working shadow jar:
plugins {
id 'application' // this allows you to set a mainClassName
id 'com.github.johnrengelman.shadow' version '6.0.0' // this adds the shadowJar task
}
group '...'
version '2.0-SNAPSHOT'
mainClassName = 'your main class goes here' // this sets the main class property in your manifest automatically
repositories {
jcenter() // jcenter is a superset of mavenCentral
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
compile 'net.dv8tion:JDA:4.2.0_191'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
compile 'com.vdurmont:emoji-java:5.1.1'
}
Run the shadowJar gradle task to compile your jar file. This will then be placed inside build/libs and has the format [name]-all.jar. Do not forget to replace the mainClassName with the fully qualified name of your main class.

Kotlin 1.3+ breaking SLF4J/log4j

I'm attempting to upgrade a project to Kotlin 1.3, but I'm facing trouble because we use HikariCP and a number of other libraries that use SLF4J/log4j and all of them get broken for some reason on Kotlin 1.3 and above.
The issue occurs just by changing the Kotlin version. Why is a change of Kotlin effecting SLF4J/log4j behavior?
java.lang.NoSuchMethodError: org.apache.log4j.Level.isGreaterOrEqual(Lorg/apache/log4j/Priority;)Z
at org.apache.log4j.Category.isDebugEnabled(Category.java:736)
at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:251)
at com.zaxxer.hikari.HikariConfig.attemptFromContextLoader(HikariConfig.java:901)
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:474)
at ps.eden.server.game.system.mysql.SQLManager.init(SQLManager.java:86)
This is the gradle build config we use, the only difference in ours is the version is 1.2.71 rather than 1.3.11:
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = "ps.eden.server.Eden"
group 'ps.eden'
version '1.4.0'
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
eclipse {
classpath {
containers 'org.jetbrains.kotlin.core.KOTLIN_CONTAINER'
}
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}
repositories {
jcenter()
flatDir { dirs 'lib' }
maven { url 'https://jitpack.io' }
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-common', version: "$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-jvm', version: "$kotlin_version"
compile group: 'org.jetbrains.kotlin', name: 'kotlin-scripting-jvm-host', version: "$kotlin_version"
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.47'
compile group: 'joda-time', name: 'joda-time', version: '2.10.1'
compile(group: 'com.zaxxer', name: 'HikariCP', version: '3.3.0') {
exclude module: 'slf4j-api'
}
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.18'
compile(group: 'org.apache.hadoop', name: 'hadoop-common', version: '3.1.1') {
exclude module: 'slf4j-api'
exclude module: 'slf4j-log4j'
exclude module: 'slf4j-log412j'
}
compile group: 'org.apache.ant', name: 'ant', version: '1.10.5'
compile group: 'it.unimi.dsi', name: 'fastutil', version: '8.2.2'
compile group: 'io.netty', name: 'netty-all', version: '4.1.32.Final'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
compile group: 'com.github.salomonbrys.kotson', name: 'kotson', version: '2.5.0'
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile 'com.github.rockaport:alice:0.9.0'
compile group: 'at.favre.lib', name: 'bcrypt', version: '0.6.0'
compile group: 'net.openhft', name: 'zero-allocation-hashing', version: '0.8'
compile('net.dv8tion:JDA:3.8.1_437') {
exclude module: 'opus-java'
}
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
}
compileJava {
options.encoding = "UTF-8"
//enable compilation in a separate daemon process
options.fork = true
//enable incremental compilation
options.incremental = true
}
You're using kotlin scripting libraries, in particular kotlin-scripting-jvm-host, which pulls the kotlin compiler jar. You can try to use kotlin-scripting-jvm-host-embeddable instead: it depends on the "embeddable" version of the compiler jar, where bundled 3-rd party classes are "shaded".
Edit: the kotlin-scripting-jvm-host-embeddable is available starting from Kotlin version 1.3.20 (at the moment of writing - only in the pre-release form).

Gradle + Spring Boot can't handle jars with more than 65535 files

Using zip64 true doesn't create a usable jar file. It can't locate the main class inside that jar, although the file, structure and location of the Manifest.mf are exactly the same as in previous builds that worked.
The real problem is: I don't need sonarqube or gatling in my final build (those are test-related), but AFAIK there is no way to exclude plugins.
The "fatJar"-task is for creating the jar.
Any kind of help is highly appreciated.
plugins {
id "org.sonarqube" version "2.2.1"
id "com.github.lkishalmi.gatling" version "0.4.1"
}
// Run in terminal with "gradle sonarqube"
sonarqube {
properties {
property "sonar.projectName", "asd"
property "sonar.projectKey", "org.sonarqube:java-gradle-simple"
property "sonar.host.url", "http://asd"
property "sonar.login", "asd"
property "sonar.password", "asd"
}
}
// Run in terminal with "gradle gatlingrun", start the application before.
gatling {
logLevel 'ERROR'
simulations = {
include "**/LoginAndSync.scala"
}
}
group 'asd'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
task fatJar(type: Jar) {
//zip64 true
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'application.Asd'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '1.4.1.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.3.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.80'
compile group: 'io.gatling.highcharts', name: 'gatling-charts-highcharts', version: '2.2.3'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.4.1.RELEASE'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.193'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '4.0.0.RELEASE'
}
This is the Exception I get:
xecution failed for task ':fatJar'.
> archive contains more than 65535 entries.
To build this archive, please enable the zip64 extension.
See: https://docs.gradle.org/3.3/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:zip64
Thanks to M.Deinum, I did a new approach:
I added spring-boot as plugin in build.gradle
plugins {
id 'org.springframework.boot' version '1.5.1.RELEASE'
}
and can now just use gradle build in the console, to get a running jar, which can be found in ./build/libs/.

hipi gradle build error

root#ubuntu:/usr/local/hipi# gradle
FAILURE: Build failed with an exception.
Where:
Build file '/usr/local/hipi/core/build.gradle' line: 8
What went wrong:
A problem occurred evaluating project ':core'.
Could not find method distributions() for arguments [build_7msgs7jcv6q1ci90h6pi2434k3$_run_closure2#39d1aa64] on project ':core'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.635 secs
Build.gradle code :
defaultTasks 'install'
allprojects {
apply plugin: 'eclipse'
}
subprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.hadoop:hadoop-common:2.7.1'
compile 'org.apache.hadoop:hadoop-mapreduce-client-core:2.7.1'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.drewnoakes:metadata-extractor:2.8.1'
compile 'com.twelvemonkeys.imageio:imageio-jpeg:3.1.1'
compile 'com.twelvemonkeys.imageio:imageio-pnm:3.1.1'
compile 'com.twelvemonkeys.imageio:imageio-tiff:3.1.1'
compile group: 'org.bytedeco', name: 'javacpp', version: '1.0'
compile group: 'org.bytedeco', name: 'javacv', version: '1.0'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'macosx-x86_64'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'linux-x86_64'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'windows-x86_64'
testCompile "junit:junit:4+"
}
}
task install {
dependsOn(':tools:hibImport:jar')
dependsOn(':tools:hibDownload:jar')
dependsOn(':tools:hibInfo:jar')
dependsOn(':tools:hibToJpeg:jar')
dependsOn(':tools:hibDump:jar')
dependsOn(':tools:covar:jar')
doLast {
println '\nFinished building the HIPI library along with all tools and examples.'
}
}
The problem is in core folder's gradle file. Can you show me that file?
The content of core's directory gradle file should be :
apply plugin: 'java-library-distribution'
jar {
baseName = 'hipi'
version = '2.1.0'
}
distributions {
main{
baseName = 'hipi'
version = '2.1.0'
}
}
javadoc {
title = "HIPI - Hadoop Image Processing Interface"
options.links("http://docs.oracle.com/javase/8/docs/api/",
"http://hadoop.apache.org/docs/stable/api/",
"http://javadoc.metadata-extractor.googlecode.com/git/2.7.0/",
"http://bytedeco.org/javacpp-presets/opencv/apidocs/")
}
test {
testLogging.showStandardStreams = true
}

How to give dependecies in multiproject in Gradle and what is the structure?

I have a multi project to be built using Gradle which has a java Project and it'll be dependancy for web Project. When I build with eclipse i have given depencies of javaProj and webProj to webprojectEAR and it works(after deployed).
.ear file needs to be created using single build run whcih has the following content.
- lib
javaProj.jar
- META-INF
- webProj.war
my project structure as follows
- javaProj
build.gradle
- webProj
build.gradle
- webProjEAR
build.gradle
- settings.gradle
I'm trying to run the webProjEAR/build.gradle file and given as dependency as follows in it.
project(':webProjEAR') {
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
}
it failed with error "Could not resolve all dependencies for configuration 'webProjEAR:testRuntime' .when I run build files separatly I am able to create jar and war files.
Please can anyone help me how dependencies should be mentioned in the build files. And, where are the madatory locations to have a build.gradle file.
=== More Information added to the original question from here ===
My build files are as below. I have made the changes Igor Popov had mentioned.
// javaProj/build.gradle
apply plugin: 'java'
repositories {
flatDir { dirs "../local-repo" }
}
sourceSets {
main {
java.srcDir "$projectDir/src"
resources.srcDir "$projectDir/XML"
}
}
jar {
from ('classes/com/nyl/xsl') {
into 'com/nyl/xsl'
}
}
dependencies {
compile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
compile group: 'slf4j-jdk14' , name: 'slf4j-jdk14' , version: '1.5.6'
compile group: 'com.ibm.xml.thinclient_1.0.0' , name: 'com.ibm.xml.thinclient_1.0.0' , version: '1.0.0'
compile group: 'junit', name: 'junit', version: '4.11'
compile group: 'saxon9' , name: 'saxon9'
compile group: 'saxon9-dom' , name: 'saxon9-dom'
compile group: 'xmlunit' , name: 'xmlunit' , version: '1.4'
}
==============================================
// webProj/build.gradle
apply plugin: 'war'
repositories {
flatDir { dirs "../local-repo" }
}
webAppDirName = 'WebContent'
dependencies {
providedCompile group: 'com.ibm.xml' , name: 'com.ibm.xml'
providedCompile group: 'com.ibm.ws.prereq.xdi2' , name: 'com.ibm.ws.prereq.xdi2'
providedCompile group: 'com.ibm.ws.xml.admin.metadata' , name: 'com.ibm.ws.xml.admin.metadata'
providedCompile group: 'guava' , name: 'guava' , version: '11.0.2'
providedCompile group: 'j2ee' , name: 'j2ee'
providedCompile group: 'slf4j-api' , name: 'slf4j-api' , version: '1.5.6'
providedCompile group: 'slf4j-log4j12' , name: 'slf4j-log4j12' , version: '1.5.6'
}
====================================================
// webProjEAR/build.gradle
apply plugin: 'java'
apply plugin: 'ear'
repositories {
flatDir { dirs "../local-repo" }
}
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
ear {
appDirName 'src/main/app'
libDirName 'APP-INF/lib'
from ('../javaProj/build/libs') {
into 'lib'
}
from ('../webProj/build/libs') {
into '/'
}
}
I would like to know what should contain in the roojProj/build.gradle file. Also like to know anything needs to be changed in the above files. Thanks
The overall structure should be something like:
rootProj
javaProj
build.gradle
webProj
build.gradle
webProjEAR
build.gradle
settings.gradle
build.gradle
The settings.gradle file should contain:
include 'javaProj', 'webProj', 'webProjEAR'
For the webProjEAR/build.gradle you can remove the project(':webProjEAR'). So it should look like:
dependencies {
compile project(':javaProj')
compile project(':webProj')
}
To fix the error you get, you should also post all your dependencies for webProjEAR (if you have others that you didn't include).

Resources