So I was given this legacy project which is built with Gradle. This project builds perfectly on linux machines with a simple ./gradlew clean build. However in my windows machine, if I execute the same command the project builts successfully but it is looking like it was a dry run of the build.
I say this because in linux the build takes me around 1 hour while in windows it takes only 50 seconds.
Additionally, I know for a fact that the build on windows is not even running the integration tests nor compiling the java, since some of the imports are even failing.
What makes this most strange is that it works on linux and not on windows.
Please advise.
I will attach the build.gradle maybe it will be useful:
subprojects {
apply plugin: "java"
apply plugin: "idea"
apply plugin: 'org.springframework.boot'
apply plugin: 'org.junit.platform.gradle.plugin'
apply from: "${rootProject.projectDir}/gradle/check/check.gradle"
bootRepackage.enabled = false
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
ext {
buildTag = project.hasProperty('buildTag') ? "-${buildTag}" : ""
assertjVersion = "3.6.2"
junitVersion = "5.3.1"
junitPlatformVersion = "1.3.1"
jitPackVersion = "1.0.0"
mockitoVersion = "2.+"
commonsLang3Version = "3.5"
commonsBeanUtilsVersion = "1.9.3"
mssqlJdbcVersion = "6.1.0.jre8"
flywayVersion = "4.1.2"
swaggerVersion = "2.7.0"
commonsIOVersion = "2.5"
awaitilityVersion = "3.0.0"
cyberSourceClientVersion = "6.2.4"
sshdVersion = "1.6.0"
springSftpVersion = "4.3.10.RELEASE"
jacksonVersion = "2.8.6"
javaxVersion = "3.1.0"
httpclientVersion = "4.5.2"
apiGuardianVersion = "1.0.0"
}
version = "1.1.6${buildTag}"
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
dependencies {
compile "org.apache.commons:commons-lang3:${commonsLang3Version}"
testCompile "org.assertj:assertj-core:${assertjVersion}"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.4.1'
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
classpath('org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4')
}
}
EDIT: After running with ./gradlew clean build --info I can see most of the tasks have NO-SOURCE or UP-TO-DATE next to them which does not happen on Linux
Related
I published a small library of mine to a free maven hosting service, and am using that package in another project. I've done this before without issue but something isn't working this time.
Gradle finds the file just fine, and downloads it I assume. I know this because any change to the URL, package name, or version, and Gradle throws the "can't find the dep in any of these places" error.
However, any import of the packages in this JAR error, saying it can't find the package. IntelliJ, when I refresh gradle deps, also doesn't show my library in the "External Libraries" section.
Here's my gradle.build for the project I'm using the library in:
apply plugin: 'java'
repositories {
maven { url = 'https://repo.repsy.io/mvn/viveleroi/tileowner' }
}
group = project.property("group")
version = project.property("version")
dependencies {
compileOnly 'network.darkhelmet.tileowner:tileowner:1.0.0'
}
compileJava {
options.compilerArgs += ["-parameters"]
options.fork = true
options.forkOptions.executable = 'javac'
}
The test class:
import network.darkhelmet.tileowner.TileOwner;
public class Demo {}
Gradle says it's on the classpath:
compileClasspath - Compile classpath for source set 'main'.
\--- network.darkhelmet.tileowner:tileowner:1.0.0
compileOnly - Compile only dependencies for source set 'main'. (n)
\--- network.darkhelmet.tileowner:tileowner:1.0.0 (n)
I've downloaded the published jar of my library from that repository, unzipped it, and have confirmed all files are in there as expected.
Here's the build.gradle of my library project:
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
dependencies {
classpath group: 'com.github.rodionmoiseev.gradle.plugins', name: 'idea-utils', version: '0.2'
}
}
plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "xyz.jpenilla.run-paper" version "1.0.6"
id 'maven-publish'
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'idea-utils'
apply plugin: 'checkstyle'
processResources {
filter ReplaceTokens, tokens: [
"apiversion": project.property("apiversion"),
"version" : project.property("version")
]
}
repositories {
mavenLocal()
mavenCentral()
maven { url = "https://repo.aikar.co/content/groups/aikar/" }
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
}
group = project.property("group")
version = project.property("version")
targetCompatibility = sourceCompatibility = JavaVersion.VERSION_17
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT'
implementation 'co.aikar:acf-bukkit:0.5.0-SNAPSHOT'
}
compileJava {
options.compilerArgs += ["-parameters"]
options.fork = true
options.forkOptions.executable = 'javac'
}
jar {
actions = []
dependsOn = []
dependsOn('shadowJar')
}
shadowJar {
relocate 'co.aikar.commands', 'network.darkhelmet.tileowner.acf'
relocate 'co.aikar.locales', 'network.darkhelmet.tileowner.locales'
}
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
}
}
repositories {
maven {
name = 'repsy'
url = 'https://repo.repsy.io/mvn/viveleroi/tileowner'
credentials(PasswordCredentials)
}
}
}
Adding clojure to an already existing gradle java project
I have a Java project that I want to start trying to add some Clojure to, but I'm hitting a few issues. I'm using the IntelliJ IDEA with the Cursive for Clojure IntelliJ plugin.
I am also using the gradle-clojure plugin for Clojure. My Java classes recognise and can call my Clojure code, but my Java code will no longer compile because at compile time it can no longer see my Clojure code.
Do I need to add an extra step in my build.gradle? Do I need to compile my Clojure separate and manually before trying to compile Java?
Any help would be greatly appreciated.
Environment
gradle-clojure v0.3.1 gradle v4.4.1Java v1.8 Intellij IDE on MacOS High Sierra
Stacktrace <> Task :compileJava FAILED java:8: error: cannot find symbol import com.example.clojure;
You can use Netflix's Clojure Wrapper, nebula.clojure.
Here is an example of a Gradle Build script for a project that uses Java and Clojure:
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "com.netflix.nebula:nebula-clojure-plugin:4.4.0"
}
}
plugins {
id "nebula.clojure" version "4.4.0"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group 'com.demo'
def artifactName = 'demo-service'
version = latestRepoTag()
static def latestRepoTag() {
def cmd = "git describe --abbrev=0"
def proc = cmd.execute();
return proc.text.trim();
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext['spring-restdocs.version'] = '1.2.1.RELEASE'
ext {
springCloudVersion = 'Dalston.SR4'
}
compileJava {
classpath = project.files(
project.compileClojure.outputs,
classpath
)
}
compileClojure {
jvmOptions {
jvmArgs '-Djava.awt.headless=true'
}
}
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
jar {
baseName = "${artifactName}"
version = latestRepoTag()
}
clojure.aotCompile = true
configurations{
dev
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR3'
}
}
dependencies {
compile 'org.clojure:clojure:1.6.0'
compile('com.google.guava:guava:19.0')
compile("commons-io:commons-io:2.5")
compile "org.apache.pdfbox:pdfbox:2.0.0-RC3"
compile("org.apache.commons:commons-lang3:3.0")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compileOnly("org.projectlombok:lombok:1.16.6")
runtime('com.h2database:h2:1.4.190')
runtime("com.ingres.jdbc:iijdbc:10.0-4.0.5")
runtime('org.apache.commons:commons-dbcp2:2.1.1')
runtime('org.postgresql:postgresql:9.4.1209')
dev("org.springframework.boot:spring-boot-devtools")
testCompile('com.jayway.jsonpath:json-path')
testCompile('com.jayway.jsonpath:json-path-assert:2.2.0')
testCompile('com.google.code.gson:gson:2.8.1')
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc:1.2.1.RELEASE")
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.dev
systemProperties = System.properties
jvmArgs = ["-client", "-Dsun.net.inetaddr.ttl=60", "-Djava.security.egd=file:/dev/./urandom"]
environment = [
'spring_profiles_active': 'beta,fast_discovery'
]
}
Here is a link to the plugin on Gradle's plugin documentation site:
I am new to gradle.
I am building a project using gradle.
It build successfully without any error. While running the build jar file it is giving classNotFoundException.
I am building a simple spring project from spring.io
However question look similar to this but, could not find a solution. Please help.
edit: This is how my build.gradle looks
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
startScripts {
mainClassName = 'Application'
}
springBoot {
mainClass = "Application"
}
You'll need to start the application with the generated start scripts. They will automatically take care of setting up the proper classpath.
I am trying to download and add JaxRS libraries with gradle. Here is the build script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jetty'
jar {
baseName = 'rest-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
compile('javax.ws.rs:jsr311-api:1.1.1')
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
try with --debug and see the URL it is using to retrieve the dependency. Then use curl or similar tool and see if it is available. If you can't get to it through your browser or curl then networking issue.
Check maven central too, maybe they don't have that version anymore. Just to validate.
I am trying to obfuscate the code of my Java project with Proguard. This project has been created on Intellij and is configured with Gradle 2.2.1. There is a proxy on the computer I work on so Intellij can not access the Internet.
I tried for hours to find a simple example to obfuscate my code.
I tried to do :
task proguardTask(type: proguard.gradle.ProGuardTask) { println "ha"}
task proguardTask(type: proguard.gradle.ProGuardTask) << { println "ha"}
and I got an exception every time :
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':proguardTask'.
> Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at proguard.ClassPath.get(ClassPath.java:77)
Here's my build.gradle file:
// Configuration des library java
project.ext.LIBJava = [
"project1",
"project2", "project2",
"project2_OS", "project2_UI",
"project3",
"project3_Windows"
]
//----------------------------------------------------------------------------------------------------------
ext.buildOnline = false
ext.buildOnlineMapsforge = false
ext.buildAndroid = false
//----------------------------------------------------------------------------------------------------------
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
buildscript {
repositories {
mavenLocal()
mavenCentral()
flatDir dirs: 'C:/Path/To/Proguard/proguard-5.1/lib'
}
dependencies {
classpath ':proguard'
}
}
def filterProjects(filter) { return subprojects.findAll { project -> filter.contains(project.name) } }
allprojects {
group = 'org.libWin'
version = '0.1.1'
}
// Configuration injection for all subprojects
subprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
//----------------------------------------------------------------------------------------------------------
task proguardTask(type: proguard.gradle.ProGuardTask) {
println "ha"
}
configure(filterProjects(project.LIBJava)) {
apply plugin: 'java'
dependencies {
if (buildOnline) { // On-line
testCompile group: 'junit', name: 'junit', version: 4.11 // "$jUnitVersion"
}
}
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
}
Does anyone know where the problem comes from ? How to obfuscate easily my code with Proguard using Gradle ?
Thanks.
You must specify injars in your Proguard task.
Example:
task proguard(type: proguard.gradle.ProGuardTask) {
injars "build/libs"
}
I could obfuscate with proguard a non-Android project with the plugin proguard-gradle .
Specify your proguard configurations (keep options) in a file
Specify input & output jars
Specify the dependencies (jars) which your project referred to.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.0.3'
classpath 'net.sf.proguard:proguard-base:6.0.3'
}
}
def dependsDir = "${buildDir}/libs/dependencies/"
def outputJar = "${buildDir}/libs/${rootProject.name}.jar"
task proguard(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.conf'
injars "${outputJar}"
outjars "${buildDir}/libs/${rootProject.name}_proguard.jar"
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
libraryjars "${dependsDir}"
}
Add the above gradle task to your build.gradle
Execute gradle proguard