Maybe I'm not setting up my dependencies properly, but Gradle insists on expanding all of my dependencies into tmp/expandedArchives which effectively makes Gradle useless. I need various JARs from WebSphere, and with Ant I would just add them to javac's classpath.
What am I doing wrong? Is there some sort of flag I can provide to my compile dependencies to just add them to the classpath?
apply plugin: 'java'
apply plugin: 'war'
dependencies {
compile fileTree(dir: '../MyEarName/lib', include: '*.jar')
compile fileTree(dir: wasHome + '/lib', include: '*.jar')
compile fileTree(dir: wasHome + '/plugins', include: '*.jar')
compile fileTree(dir: wasHome + '/runtimes', include: '*.jar')
compile fileTree(dir: wasHome + '/java/jre/lib', include: '*.jar')
}
war {
webAppDirName = 'WebContent'
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceSets {
main {
java {
srcDir 'src'
}
}
}
compileJava {
options.fork = true
options.incremental = true
}
Thank you!
Turns out this was because options.incremental = true. Removing that fixed the problem.
Search for hours, finally post to SO, figure out the answer shortly after...
Related
I have 3 modules: annotations, annotation_processor and app.
annotations/build.gradle
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
annotation_processor/build.gradle
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api project(":annotations")
api "com.squareup:javapoet:1.11.1"
}
repositories {
mavenCentral()
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
task deleteJar(type: Delete) {
delete 'libs/annotations.jar'
}
task createJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('libs/')
include('classes.jar')
rename('classes.jar', 'annotations.jar')
}
createJar.dependsOn(deleteJar, build)
and app/build.gradle
dependencies {
...
implementation files('libs/annotation_processor.jar')
annotationProcessor files('libs/annotation_processor.jar')
...
}
When I run the project I get the following error.
error: package com.annotations does not exist
If I include annotations as a project the project I can skip this error but then I get.
Caused by: java.lang.NoClassDefFoundError: com/annotations/ProviderApi
at com.annotation_processor.ProviderAnnotationProcessor.getSupportedAnnotationTypes(ProviderAnnotationProcessor.java:45)
at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.getSupportedAnnotationTypes(DelegatingProcessor.java:47)
at org.gradle.api.internal.tasks.compile.processing.NonIncrementalProcessor.getSupportedAnnotationTypes(NonIncrementalProcessor.java:33)
at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.getSupportedAnnotationTypes(DelegatingProcessor.java:47)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.access$101(TimeTrackingProcessor.java:37)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor$2.create(TimeTrackingProcessor.java:68)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor$2.create(TimeTrackingProcessor.java:65)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.track(TimeTrackingProcessor.java:117)
at org.gradle.api.internal.tasks.compile.processing.TimeTrackingProcessor.getSupportedAnnotationTypes(TimeTrackingProcessor.java:65)
I can't access any of the dependencies (Java Poet and annotation module) from annotation_processor even though I have replaced implementation with api. Which should've expose the dependencies, but haven't.
I need the dependencies of the .jar file in the app module.
I'm new to Java Library and it may be I'm making a basic mistake, but can't seem to figure out, I've been at it for more than a day now.
You have to create a multi module gradle project.
I provide a small snippet of a multi module project.
project(':module1') {
dependencies {
compile project(':module-service-api')
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'log4j:log4j:1.2.17'
}
}
//module-app depends on module-service-impl
project(':module2') {
dependencies {
compile project(':module1')
}
For more details about multi module project, refer to the file build.gradle in the following project.
https://github.com/debjava/gradle-multi-module-project-1
If you want to create a fat jar or one jar, you have to include Gradle shadow plugin so that you can distribute the jar file along with other dependencies.
Refer below the link.
https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow
Hello I have the following problem using Dagger 2 in my (part) project being completely pure-Java with no android dependencies.
When I run the unit tests using some mocks (e.g. Injecting a Mock Network Connector returning static Strings) over the Gradle view or console (businessModule:test) there are no problems and all tests Succeed. But when I open the files in Android Studio the Studio says that the Return of my DaggerMockComponent is not compatible with the target type. Opening the generated Component-Implementation, I see that Android Studio thinks the TestUnit-Class (and the interface MockComponent) is not available so it does not know what the inject method returns.
I have the following gradle file:
apply plugin: 'java'
// allow inject of core into core. https://github.com/griffio/dagger2-example
sourceSets {
dagger {
java {
srcDirs = ['src/dagger/java']
}
}
daggerTest {
java {
srcDirs = ['src/daggerTest/java']
}
}
}
configurations {
compileDagger
}
compileJava {
description = "dagger annotation processor is loaded automatically from classpath"
sourceSets.dagger.java.srcDirs*.mkdirs()
classpath += configurations.compileDagger
options.compilerArgs += [
'-s', sourceSets.dagger.java.srcDirs.iterator().next()
]
}
compileTestJava {
//dependsOn compileDaggerTestJava
description = "dagger annotation processor is loaded automatically from classpath"
sourceSets.daggerTest.java.srcDirs*.mkdirs()
classpath += configurations.compileDagger
options.compilerArgs += [
'-s', sourceSets.daggerTest.java.srcDirs.iterator().next()
//'-s src/testDaggerJava'
]
}
task deleteDagger(type: Delete) {
delete 'src/dagger', 'src/daggerTest'
}
clean.dependsOn deleteDagger
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Force Java 7 as newer versions can not be processed by dex for API 21
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
[...]
// Dagger for dependency injection
compile 'com.google.dagger:dagger:2.8'
testCompile 'com.google.dagger:dagger:2.8'
compileOnly 'com.google.dagger:dagger-compiler:2.8'
testCompileOnly 'com.google.dagger:dagger-compiler:2.8'
[...]
testCompile 'junit:junit:4.12'
}
Thanks for your help.
Ok everybody, after an additional night and some research on the android-apt plugin I stumbled over the pure-Java apt (net.ltgt.apt) and now I have a working solution in combination with the idea-plugin
apply plugin: 'java'
apply plugin: "net.ltgt.apt"
apply plugin: "idea"
task cleanGenerated(type: Delete) {
delete 'build'
}
clean.dependsOn cleanGenerated
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Force Java 7 as newer versions can not be processed by dex for API 21
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
[...]
// Dagger for dependency injection
compile 'com.google.dagger:dagger:2.8'
apt 'com.google.dagger:dagger-compiler:2.8'
testCompile 'com.google.dagger:dagger:2.8'
testApt 'com.google.dagger:dagger-compiler:2.8'
[...]
testCompile 'junit:junit:4.12'
}
Of course you have to add the dependency and plugin-name in the root gradle file but that is written down in the documentation for net.ltgt.apt - hope this works for you, too.
I'm using libGDX for my game which shares some code with another project. I put this code in a .jar library which I have added in the root build.gradle.
Everything works fine on desktop, but when I launch the game on Android it crashes with a ClassNotFound exception. It can't find a class of my the library.
Can anyone help me out? I have no idea what is causing the problem.
Edit: changes to build.gradle:
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile fileTree(dir: '../libs', include: '*.jar')
}
}
You need to add the same fileTree dependency directly in the android module because the Android Gradle plugin currently can't handle transitive flat file dependencies.
project(":core") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
// And also
project(":android") {
...
compile fileTree(dir: '../libs', include: '*.jar')
...
}
Source.
I am trying to update my library for the project by adding following dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:22.1.1"
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Unfortunately, I am getting error as:
Error:(30, 13) Failed to resolve: com.mcxiaoke.volley:library:1.0.19
Error:(23, 17) Failed to resolve: junit:junit:4.12
The problem occurred because you used jar file that is deprecated and no longer being maintained.
Use this to include volley library:
compile 'com.android.volley:volley:1.0.0'
instead of compile 'com.mcxiaoke.volley:library:1.0.19' as volley dependency.
Keep tracking here: https://github.com/google/volley
for now it's:
compile 'com.android.volley:volley:1.1.0'
Add mavenCentral() at project level build gradle file `
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir}
I have 2 gradle projects: an Android app and a RoboSpock test.
My build.gradle for the Android app has
. . .
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile ('com.actionbarsherlock:actionbarsherlock:4.4.0#aar') {
exclude module: 'support-v4'
}
}
. . .
and builds correctly by itself, e.g assembleRelease works.
I'm stuck getting the test to work. I gets lots of errors such as:
package com.google.zxing does not exist
Those seem to indicate that the .jar files aren't being picked up.
Here's my build.gradle for the test project:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'org.robospock:robospock-plugin:0.4.0'
}
}
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'groovy'
dependencies {
compile "org.codehaus.groovy:groovy-all:1.8.6"
compile 'org.robospock:robospock:0.4.4'
}
dependencies {
compile fileTree(dir: ':android:libs', include: '*.jar')
compile (project(':estanteApp')) {
transitive = true
}
}
sourceSets.test.java.srcDirs = ['../android/src/', '../android/build/source/r/debug']
test {
testLogging {
lifecycle {
exceptionFormat "full"
}
}
}
project.ext {
robospock = ":estanteApp" // project to test
}
apply plugin: 'robospock'
As that shows, I've tried adding transitive = true and including the .jar files explicitly. But no matter what I try, I end up with the package does not exist error.
In Android Studio you no longer need a different project for testing. Put your testing code in the same module under "src/androidTest/java"
Then add the following to "build.gradle" in the "defaultConfig"
testPackageName "com.yourpackage.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testFunctionalTest true