gradlew complie has no lib.jar - gradle

I am using gradle(Gradle 4.7) to compile a project(Java 1.8) has multimodule:
./gradlew -p web -x test build
and one of it has no dist jar,the others has,what's the problem?the normal dir structure of compile output:
--build
----classes
----libs
----tmp
and the abnormal dir structure:
--build
----classes
----tmp
This is the build.gradle(abnormal module):
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
PS: all module does not generate libs folder,the libs is cache.Why the module does not generate dis jar file,How to configure my gradle project.This is the full config of my project:
group 'dolphin'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
springVersion = '4.3.7.RELEASE'
springfoxVersion = '2.6.1'
jacksonVersion = '2.8.7'
lombokVersion = '1.16.14'
}
ext['tomcat.version'] = '9.0.16'
repositories {
mavenCentral()
jcenter{
url 'http://jcenter.bintray.com'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
def getVersionCode() {
def versionFile = file("$rootDir/version.properties")
if (!versionFile.canRead()) {
throw new GradleException("Could not find version.properties!")
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def versionCode = versionProps['VERSION'].toString()
return versionCode
}
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.7'
}
project(":common") {
description = ''
dependencies {
api("org.springframework:spring-context:" + springVersion)
api("commons-codec:commons-codec:1.10")
api("org.apache.tomcat:tomcat-juli:" + property('tomcat.version'))
api 'org.springframework.boot:spring-boot-starter-web'
api group: 'io.swagger', name: 'swagger-annotations', version: '1.5.20'
api("org.projectlombok:lombok:${lombokVersion}")
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
api group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.0'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.4'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
}
}
project(":composite") {
description = 'dolphin-composite'
dependencies {
implementation project(":monitor-business")
api project(":data")
implementation("org.springframework:spring-context:" + springVersion)
}
}
project(":web") {
description = "web"
archivesBaseName = "dolphin-web-" + getVersionCode()
jar {
// Will include every single one of your dependencies, project or not
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
dependencies {
api project(':monitor-business')
api project(':api')
api project(':common')
api project(':data')
api project(':composite')
implementation("com.zaxxer:HikariCP:2.6.0")
api("org.mybatis:mybatis-spring:1.3.0")
implementation("mysql:mysql-connector-java:5.1.24")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter")
implementation("io.springfox:springfox-swagger2:2.9.2")
implementation("io.springfox:springfox-swagger-ui:2.9.2")
implementation group: 'org.apache.tomcat', name: 'tomcat-juli', version: property('tomcat.version')
implementation("org.projectlombok:lombok:1.16.14")
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
implementation group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
implementation group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
project(":monitor-business") {
description = "business"
dependencies {
api project(':data')
api project(':common')
implementation('org.springframework.boot:spring-boot-starter-web')
}
}
project(":data") {
description = "data"
dependencies {
api project(':common')
api("org.projectlombok:lombok:${lombokVersion}")
implementation("com.zaxxer:HikariCP:2.6.0")
implementation group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
api("org.hibernate:hibernate-validator:5.2.4.Final")
api("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1")
api("org.apache.commons:commons-lang3:3.5")
api group: 'org.springframework', name: 'spring-jdbc', version: '5.1.5.RELEASE'
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
api group: 'org.mybatis', name: 'mybatis', version: '3.4.2'
api group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
api("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
}
}
PS:My problem is like this memo: https://discuss.gradle.org/t/gradle-4-x-jar-is-not-generated/24773
I have solved it but don't know why....

To solve the problem,using this command to build the project(It will generate the libs folder and jar file):
./gradlew -p web -x test -x jar build
Gradle version:4.7.(Gradle 5.3 not work)

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.

Why SpotBugs Gradle plugin always generate XML report instead of HTML?

I am using Gradle 5.2, spotbugs-gradle-plugin version 2.0.0 and tried to generate SpotBugs report on my project. I used the following configuration on my project but it always create XML reports instead of html report.
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:+'
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0"
}
}
allprojects {
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.github.spotbugs'
group = 'com.myproject'
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
compile('com.google.cloud:google-cloud-storage:+') {
exclude group: "com.google.guava", module: "guava"
}
compile group: 'org.apache.commons', name: 'commons-collections4', version: '+'
compile group: 'com.google.guava', name: 'guava', version: '+'
testImplementation('org.junit.jupiter:junit-jupiter:+')
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
}
project(':myproject') {
dependencies {
compile group: 'com.github.javafaker', name: 'javafaker', version: '+'
compile group: 'org.jsonschema2pojo', name: 'jsonschema2pojo-core', version: '+'
compile group: 'commons-lang', name: 'commons-lang', version: '+'
compile group: 'org.mongodb', name: 'bson', version: '+'
}
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
spotbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
What I did wrong here?
Kindly provide your inputs to create HTML report instead of XML!

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/.

How to build on travis-ci with gradle and cobertura

Today I've tried to connect my travis-ci with coveralls using cobertura reports. Unfortunatelly after adding cobertura to my project travis cannot succeed in building my project.
Here's exemplary build: https://travis-ci.org/bandrzejczak/activiti-console-rest/jobs/38356310
And here's my build.gradle file:
plugins {
id 'java'
id 'war'
id 'idea'
id 'net.saliman.cobertura' version '2.2.5'
id 'com.github.kt3k.coveralls' version '2.0.1'
}
sourceCompatibility = 1.7
version = '0.0.1'
repositories {
mavenCentral()
maven{
url 'http://maven.restlet.org'
}
}
dependencies {
//compile dependencies
compile group: 'org.jetbrains', name: 'annotations', version: '13.0'
compile group: 'org.activiti', name: 'activiti-engine', version: '5.15.1'
compile group: 'org.activiti', name: 'activiti-spring', version: '5.15.1'
compile group: 'org.restlet.jee', name: 'org.restlet', version: '2.2.1'
compile group: 'org.restlet.jee', name: 'org.restlet.ext.spring', version: '2.2.1'
compile group: 'org.restlet.jee', name: 'org.restlet.ext.jackson', version: '2.2.1'
compile group: 'org.reflections', name: 'reflections', version: '0.9.8'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.6'
//runtime dependencies
runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.31'
//test dependencies
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'org.springframework', name: 'spring-test', version: '3.2.7.RELEASE'
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.3'
testRuntime group: 'com.h2database', name: 'h2', version: '1.4.178'
testRuntime group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
cobertura.coverageFormats = ['html', 'xml']
I've found the answer to my question but I've forgotten to post it here. My mistake came from using wrong coveralls plugin. This is what you need to use when faced with such a problem:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.0'
}
}
apply plugin: 'com.github.kt3k.coveralls'
You can see whole build.gradle that I've used here.

Resources