I have an existing Spring app that I want to convert to a Spring Boot app. So I have added th Application.java file in my java source directory and execute my gradlwe script as usual. However, when I run the build command, a get an error saying 'unable to access jarfile' - although I specify the jarfile name in my build script and on my command line. Below is the build.gradle file and the output. What is wrong here?
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'
archivesBaseName = 'spring4'
version = '1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.3.RELEASE'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
compile 'mysql:mysql-connector-java:5.1.31'
compile 'commons-dbcp:commons-dbcp:1.4'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE'
compile "ch.qos.logback:logback-classic:1.1.3"
compile "org.slf4j:log4j-over-slf4j:1.7.13"
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
testCompile("junit:junit")
}
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
configurations.all {
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
}
sourceSets {
main {
resources {
srcDirs "src/main/resources"
}
}
}
output:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:findMainClass
:war
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 11.772 secs
Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$
check target directory:
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$ ll build/libs/
total 53697
drwxrwxrwx 1 vagrant vagrant 0 Sep 15 11:25 ./
drwxrwxrwx 1 vagrant vagrant 4096 Sep 13 09:54 ../
-rwxrwxrwx 1 vagrant vagrant 30698749 Sep 15 11:25 spring4-1.war*
-rwxrwxrwx 1 vagrant vagrant 24281990 Sep 15 11:24 spring4-1.war.original*
vagrant#vagrant:/vagrant/Spring4RESTAngularJS$
Related
I am facing this issue during gradle build:
org.gradle.tooling.BuildException: Failed to execute aapt
at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:547)
at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.doFullTaskAction(LinkApplicationAndroidResourcesTask.java:280)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.ide.common.process.ProcessException: Failed to execute aapt
at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)
at com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask.invokeAaptForSplit(LinkApplicationAndroidResourcesTask.java:525)
... 49 more
Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing process /home/local/MPROGA1/malwinder.singh/Desktop/SDK/android-sdk-linux/build-tools/27.0.1/aapt with arguments {package -f --no-crunch -I /home/local/MPROGA1/malwinder.singh/Desktop/SDK/android-sdk-linux/platforms/android-25/android.jar -M /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/res/merged/debug -m -J /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/generated/source/r/debug -F /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/res/debug/resources-debug.ap_ -D /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/multi-dex/debug/manifest_keep.txt --custom-package com.emerson.oversight -0 apk --output-text-symbols /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/symbols/debug --no-version-vectors}
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:792)
... 50 more
Caused by: com.android.ide.common.process.ProcessException: Error while executing process /home/local/MPROGA1/malwinder.singh/Desktop/SDK/android-sdk-linux/build-tools/27.0.1/aapt with arguments {package -f --no-crunch -I /home/local/MPROGA1/malwinder.singh/Desktop/SDK/android-sdk-linux/platforms/android-25/android.jar -M /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/res/merged/debug -m -J /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/generated/source/r/debug -F /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/res/debug/resources-debug.ap_ -D /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/multi-dex/debug/manifest_keep.txt --custom-package com.emerson.oversight -0 apk --output-text-symbols /home/local/MPROGA1/malwinder.singh/Desktop/Oversight/app/build/intermediates/symbols/debug --no-version-vectors}
at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:73)
at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:48)
at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:78)
at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:74)
at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1237)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:911)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:822)
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:664)
at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:48)
at com.android.build.gradle.internal.process.GradleProcessExecutor$1.run(GradleProcessExecutor.java:58)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/home/local/MPROGA1/malwinder.singh/Desktop/SDK/android-sdk-linux/build-tools/27.0.1/aapt'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:382)
at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:46)
... 9 more
Module level (inner) build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
//For green dao
apply plugin: 'org.greenrobot.greendao'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
jcenter()
}
android {
compileSdkVersion 25
buildToolsVersion '27.0.1'
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 25
versionCode 3
versionName "1.1.1"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.6.7#aar') {
transitive = true
}
//AppCompat v7 support library
compile 'com.android.support:appcompat-v7:25.3.1'
//AppCompat v4 support library
compile 'com.android.support:support-v4:25.3.1'
//Support design
compile 'com.android.support:design:25.3.1'
//Google Maps
compile 'com.google.android.gms:play-services-maps:11.8.0'
//Retrofit - for making REST API calls
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//For Runtime permissions
compile 'com.karumi:dexter:4.2.0'
//To set custom fonts
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
//Attaches bullets to viewpager
compile 'com.robohorse.pagerbullet:pagerbullet:1.0.8'
//Expandable recycler view
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
//For Graph
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
//Date time
compile 'com.wdullaer:materialdatetimepicker:3.2.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.android.support:cardview-v7:25.3.1'
// jCenter
compile 'jp.wasabeef:recyclerview-animators:2.2.6'
compile 'com.ncornette.cache:okcache-control:1.1.1'
compile 'org.greenrobot:greendao:3.2.2'
compile 'net.danlew:android.joda:2.9.9'
compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.3'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'org.jetbrains.anko:anko-common:0.8.3'
compile 'me.dm7.barcodescanner:zbar:1.9.8'
// https://mvnrepository.com/artifact/com.openhtmltopdf/openhtmltopdf-parent
compile group: 'com.openhtmltopdf', name: 'openhtmltopdf-parent', version: '0.0.1-RC12', ext: 'pom'
}
Main (Outer) build.gradle:
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha06'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This issue is not coming on Android Studio 3.0.1
try this. I tried , it is working.
Android Studio > Help > Check For Update > Configure and select Canary Channel on spinner and click ok. After clean project and re build .
I had the same error as i added a dependency that uses the compile sdk version and the target sdk version greater to that of my project's compile sdk version.
My projects Compile sdk version was 26
I added the easy permissions library that uses the compile sdk version 28.
After adding the 'implementation 'pub.devrel:easypermissions:2.0.1'' above error was thrown.
Fix was to made my compile sdk version to 28.
Reason:
A library is compiled as part of the dependent application project, so the API used in >the library project must be compatible with the version of the Android library used to >compile the application project. In general, the library project should use an API level >that is the same as — or lower than — that used by the application. If the library >project uses an API level that is higher than that of the application, the application >project will not compile. It is perfectly acceptable to have a library that uses the >Android 1.5 API (API level 3) and that is used in an Android 1.6 (API level 4) or >Android 2.1 (API level 7) project, for instance.
Try adding:
implementation 'com.android.support.constraint: constraint-layout: 1.0.2'
In your build.gradle {} dependencies
In my case that was the problem, maybe some xml resources need to use constraint-layout......
This is my build file. I'm using Intellij CE. I'm trying to use this yahoo finance api:
group 'com.scrap'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.yahoofinance-api', name: 'YahooFinanceAPI', version: '4.0.0'
compile 'joda-time:joda-time:2.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
When I manually sync the project in the Gradle tool window, I get a red line under the yahoofinance library and a message that says
unable to resolve com.yahoofinance-api:YahooFinanceAPI:4.0.0
What am I doing wrong?
4.0 YahooFinanceAPI does not exist in Maven. The latest one is 3.5.0 - cf - https://mvnrepository.com/artifact/com.yahoofinance-api/YahooFinanceAPI
Tested by modify the version and adding an option for creating a fat jar
group 'com.scrap'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.yahoofinance-api', name: 'YahooFinanceAPI', version: '3.5.0' //Changed version
compile 'joda-time:joda-time:2.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
// Added new section
jar {
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes("Main-Class": "Main" )
}
}
Ran gradle clean build and the dependencies download
$ gradle clean build
Download https://repo1.maven.org/maven2/com/yahoofinance-api/YahooFinanceAPI/3.5.0/YahooFinanceAPI-3.5.0.pom
Download https://repo1.maven.org/maven2/com/yahoofinance-api/YahooFinanceAPI/3.5.0/YahooFinanceAPI-3.5.0.jar
Download https://repo1.maven.org/maven2/joda-time/joda-time/2.2/joda-time-2.2.jar
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 10.199 secs
why does the Class-Path include Groovy, and why is it packaged as if it's a run-time dependency? What is pulling Groovy in?
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ gradle clean assemble
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
hello_api-dev.jar groovy-all-2.4.1.jar
:startScripts
:distTar
:distZip
:assemble
BUILD SUCCESSFUL
Total time: 2.401 secs
thufir#mordor:~/NetBeansProjects/hello_client$
The Groovy JAR's are included in the distribution as well:
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ unzip build/distributions/hello_client-dev.zip
Archive: build/distributions/hello_client-dev.zip
creating: hello_client-dev/
creating: hello_client-dev/lib/
inflating: hello_client-dev/lib/hello_client-dev.jar
inflating: hello_client-dev/lib/hello_api-dev.jar
inflating: hello_client-dev/lib/groovy-all-2.4.1.jar
creating: hello_client-dev/bin/
inflating: hello_client-dev/bin/hello_client.bat
inflating: hello_client-dev/bin/hello_client
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ java -jar hello_client-dev/lib/hello_client-dev.jar
hello [fred]
thufir#mordor:~/NetBeansProjects/hello_client$
The build.groovy file:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
mainClassName = 'net.bounceme.mordor.hello.client.HelloClient'
version = 'dev'
group = 'com.some.project'
description = 'hello world KISS'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
if (!hasProperty(mainClassName)) {
ext.mainClass = mainClassName
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.10'
compile 'com.github.THUFIR:hello_api:dev'
}
jar.doFirst
{
def manifestClasspath = configurations.runtime.collect { it.name }
manifestClasspath = manifestClasspath.unique().join(" ")
println (manifestClasspath)
manifest.attributes.put("Main-Class", mainClassName)
manifest.attributes.put("Class-Path", manifestClasspath)
}
I think that the solution lies in dealing with configurations.runtime.collect in that Groovy should be removed from that collection. It just seems odd that it's included implicitly. Is this typical, to include Groovy?
The notion of a providedCompile looks interesting, but I'm not sure that it applies. Am I using Gradle in an odd way somehow?
The library and client repos are on github. Code posted might not be 100% as the latest commits, to make the questions as clear as possible.
A very brief search explained to how to package run time dependencies for distribution:
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ gradle clean build
Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 9.237 secs
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ java -jar build/libs/hello_client.jar
hello [fred]
thufir#mordor:~/NetBeansProjects/hello_client$
with the desired output. However, the suggested solution, a "fat jar", results in this monstrosity:
thufir#mordor:~/NetBeansProjects/hello_client$
thufir#mordor:~/NetBeansProjects/hello_client$ jar -ft build/libs/hello_client.jar
META-INF/
META-INF/MANIFEST.MF
net/
net/bounceme/
net/bounceme/mordor/
net/bounceme/mordor/hello/
net/bounceme/mordor/hello/client/
net/bounceme/mordor/hello/client/HelloClient.class
net/bounceme/mordor/hello/library/
net/bounceme/mordor/hello/library/HelloLibrary.class
META-INF/ANTLR-LICENSE.txt
META-INF/ASM-LICENSE.txt
META-INF/CLI-LICENSE.txt
META-INF/JSR223-LICENSE.txt
META-INF/LICENSE.txt
META-INF/NOTICE.txt
META-INF/dgminfo
META-INF/groovy-release-info.properties
META-INF/maven/
META-INF/maven/commons-cli/
META-INF/maven/commons-cli/commons-cli/
META-INF/maven/commons-cli/commons-cli/pom.properties
META-INF/maven/commons-cli/commons-cli/pom.xml
META-INF/services/
META-INF/services/javax.script.ScriptEngineFactory
META-INF/services/org.codehaus.groovy.plugins.Runners
META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
META-INF/services/org.codehaus.groovy.source.Extensions
META-INF/services/org.codehaus.groovy.transform.ASTTransformation
groovy/
groovy/beans/
groovy/beans/Bindable.class
groovy/beans/BindableASTTransformation.class
which then goes on seemingly endlessly. Obviously, I don't want to include groovy in the fat jar. How can I exclude groovy from the built JAR?
build file:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
mainClassName = 'net.bounceme.mordor.hello.client.HelloClient'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
if (!hasProperty(mainClassName)) {
ext.mainClass = mainClassName
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.10'
compile 'com.github.THUFIR:hello_api:dev'
}
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes ('Main-Class': mainClassName,
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
}
assemble.dependsOn (jar)
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
what alternatives are there to:
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
Admittedly, I haven't learned the Groovy DSL and am just kludging together bits and pieces so far.
I believe that I saw mention of subtracting one set of dependencies from another to minimize the included libraries. However, in the odd case that there are libraries which aren't required to compile, but are required to execute the JAR, I'm not sure how that would work.
Building a model with gradle in eclipse 4.4.1 (luna) gives me an error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project '10-VideoServiceWithMongoDB'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE.
Required by:
:10-VideoServiceWithMongoDB:unspecified
> org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
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: 3.454 secs
running it through a command line through jettyRun I can get more information
* Exception is:
org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':classpath'.
at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.rethrowFailure(DefaultLenientConfiguration.java:52)
at org.gradle.api.internal.artifacts.ivyservice.DefaultResolvedConfiguration.rethrowFailure(DefaultResolvedConfiguration.java:36)
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$FilesAggregatingResolvedConfiguration.rethrowFailure(SelfResolvingDependencyResolver.java:104)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration.rethrowFailure(ErrorHandlingArtifactDependencyResolver.java:72)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:461)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:202)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
at org.gradle.api.internal.initialization.DefaultScriptHandler.updateClassPath(DefaultScriptHandler.java:36)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:118)
at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:466)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:77)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
at org.gradle.api.internal.Actions$CompositeAction.execute(Actions.java:78)
at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(Actions.java:130)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:442)
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:437)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:40)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.gradle.api.internal.artifacts.ivyservice.ModuleVersionResolveException: Could not resolve org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE.
Required by:
:10-VideoServiceWithMongoDB:unspecified
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.resolve(UserResolverChain.java:65)
at org.gradle.api.internal.artifacts.ivyservice.clientmodule.ClientModuleResolver.resolve(ClientModuleResolver.java:36)
at org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectDependencyResolver.resolve(ProjectDependencyResolver.java:45)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.LazyDependencyToModuleResolver$StaticVersionResolveResult.resolve(LazyDependencyToModuleResolver.java:91)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$ModuleVersionSelectorResolveState.resolve(DependencyGraphBuilder.java:939)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DefaultModuleRevisionResolveState.getDescriptor(DependencyGraphBuilder.java:645)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.calculateTargetConfigurations(DependencyGraphBuilder.java:329)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.attachToTargetConfigurations(DependencyGraphBuilder.java:305)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:128)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:64)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:69)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:36)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:34)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:130)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:53)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:34)
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:39)
at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:44)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:37)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveNow(DefaultConfiguration.java:240)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getResolvedConfiguration(DefaultConfiguration.java:230)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getResolvedConfiguration(Unknown Source)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:459)
... 35 more
Caused by: java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:75)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:131)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:165)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:485)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:158)
at org.apache.http.impl.client.DecompressingHttpClient.execute(DecompressingHttpClient.java:139)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performHttpRequest(HttpClientHelper.java:111)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.executeGetOrHead(HttpClientHelper.java:87)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:78)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performRawGet(HttpClientHelper.java:66)
at org.gradle.api.internal.externalresource.transport.http.HttpClientHelper.performGet(HttpClientHelper.java:70)
at org.gradle.api.internal.externalresource.transport.http.HttpResourceAccessor.getResource(HttpResourceAccessor.java:46)
at org.gradle.api.internal.externalresource.transport.http.HttpResourceAccessor.getResource(HttpResourceAccessor.java:32)
at org.gradle.api.internal.externalresource.transfer.ProgressLoggingExternalResourceAccessor.getResource(ProgressLoggingExternalResourceAccessor.java:37)
at org.gradle.api.internal.externalresource.transfer.DefaultCacheAwareExternalResourceAccessor.getResource(DefaultCacheAwareExternalResourceAccessor.java:54)
at org.gradle.api.internal.externalresource.transport.DefaultExternalResourceRepository.getResource(DefaultExternalResourceRepository.java:65)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.getResource(ExternalResourceResolver.java:572)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.findStaticResourceUsingPattern(ExternalResourceResolver.java:455)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.findResourceUsingPattern(ExternalResourceResolver.java:446)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.findResourceUsingPatterns(ExternalResourceResolver.java:368)
at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.findIvyFileRef(MavenResolver.java:166)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver.getDependency(ExternalResourceResolver.java:156)
at org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver.getDependency(MavenResolver.java:76)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ExternalResourceResolverAdapter.getDependency(ExternalResourceResolverAdapter.java:35)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockingModuleVersionRepository$1.run(CacheLockingModuleVersionRepository.java:50)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.longRunningOperation(DefaultCacheLockingManager.java:49)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CacheLockingModuleVersionRepository.getDependency(CacheLockingModuleVersionRepository.java:48)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleVersionRepository.getDependency(CachingModuleVersionRepository.java:88)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.IvyContextualiser$1.invoke(IvyContextualiser.java:44)
at com.sun.proxy.$Proxy19.getDependency(Unknown Source)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain$RepositoryResolveState.resolve(UserResolverChain.java:185)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.findLatestModule(UserResolverChain.java:97)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.findLatestModule(UserResolverChain.java:80)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain.resolve(UserResolverChain.java:54)
I have read [this][1] but after adding the extra lines in my .ini file for eclipse, nothing changed. I have tried changing my java version from 1.8 to 1.6openJDK. I am on Ubuntu 14.
edit
here's the build file
uildscript {
ext {
springBootVersion = '1.0.2.RELEASE'
}
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
war {
baseName = 'videosvc-mongodb'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
maven { url "http://maven.springframework.org/milestone" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
providedRuntime("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.data:spring-data-rest-webmvc")
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("com.google.guava:guava:17.0")
compile("com.squareup.retrofit:retrofit:1.6.0")
compile("commons-io:commons-io:2.4")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
When I try to refresh the Gradle dependecy by running gradle -refresh--dependencies in the apps folder I get a new fun error:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jake/mobilecloud-14/examples/10-VideoServiceWithMongoDB/build.gradle' line: 17
* What went wrong:
A problem occurred evaluating root project '10-VideoServiceWithMongoDB'.
> org.gradle.api.tasks.TaskContainer.create(Ljava/lang/String;Ljava/lang/Class;)Lorg/gradle/api/Task;
[1]: http://stackoverflow.com/questions/26085045/error-at-building-model-of-new-gradle-project-for-libgdx
Okay, so apparently Gradle didn't like my java build. I switched it to java-7-oracle by using this method