is this a gradle eclipse task bug or inconsistent on purpose? - gradle

So I have the following dependencies section in gradle
dependencies {
compile project(':sdi-master')
compile fileTree(dir: '../webserver/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: '../webserver/play-1.2.4/framework', include: 'play-*.jar')
}
I also have a copy jars task like so
task deleteJars(type: Delete) {
ext.collection = files { genLibDir.listFiles() }
delete ext.collection
}
task copyJars(type: Copy) {
from(configurations.compile) {}
into genLibDir
}
copyJars.dependsOn('deleteJars')
classes.dependsOn('copyJars')
Notice how it depends on sdi-master which then has ONE compile fileTree as well. When I run copyJars, as expected, I get all the jars from the sdi-master as well copied into genLibDir. When I run the eclipse task however, those jars do NOT show up in the .classpath file as I would expect so my project doesn't compile in eclipse.
Is this a gradle eclipse task bug I need to report or is this supposed to be the behavior(though it seems very inconsistent with the copy jars using configurations.compile.
thanks,
Dean

Eclipse understands transitive dependencies, so the dependencies of sdi-master will not (and should not) show up in the current project's .classpath file. They should just show up in sdi-master's .classpath file and should be marked as exported there.

Related

How Can I Use An Extracted Dependency As A Dependency In Gradle?

Some of my dependencies are in Artifactory as zip files that have been distributed by a vendor.
The jars are required to compile and the dll/so and html templates are required for debugging/runtime.
Creating a dependency on local files is straightforward:
dependencies {
compile fileTree(dir: "${projectDir}/sec-lib", includes: ['*.jar'])
}
Extracting dependencies is straightforward too:
dependencies {
compile 'com.thirdparty.sec-lib:1.0#zip'
}
task copyToLib(type: Copy) {
into "${projectDir}/sec-lib"
from configurations.compile
}
How do I use them together though?
I can change the zip to a new configuration so only that one is extracted:
configurations {
zipCompile
}
dependencies {
zipCompile 'com.thirdparty.sec-lib:1.0#zip'
compile fileTree(dir: "${projectDir}/sec-lib", includes: ['*.jar'])
}
task copyToLib(type: Copy) {
into "${projectDir}/sec-lib"
from configurations.zipCompile
}
However, the copyToLib task has to run in order for the dependencies to resolve but the dependencies need to resolve for the copyToLib task to run.
How do I fix this circular dependency issue?
I don't want to have to have a README that says "make sure you run this task first or the project wont compile or import into your IDE".
I also have multiple zip files like this I need to deal with.

How to add external jars to build.gradle from local system folder

I have created a custom plugin in groovy. now i want to add it to my build.gradle in another project:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Above lines does not seem to work for me. i have put my external jar in libs folder in project root folder. I am getting error plugin with id not found.Please correct me if i am wrong.

How can I clone a repo from GitHub using gradle?

I have a project which depends on other repos. My goal is to write a gradle task that clones the required repos automatically.
The problem I am having is that when I run my task, gradlew fails because it tries to compile the project dependencies before running my task. Here is what I have:
settings.gradle
include ':app'
include 'testRepo'
project(':testRepo').projectDir = new File('../testRepo')
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'org.ajoberstar:gradle-git:1.5.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
build.gradle(app)
task clone << {
Grgit.clone(dir: file('../testRepo'), uri: "https://github.com/fakeAccount/testRepo.git")
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':testRepo')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
}
When I do ./gradlew clone I get:
"Cannot evaluate module testRepo : Configuration with name 'default' not found"
This is because it tries to compile the testRepo project before cloning from GitHub. If I take out the compile project(':testRepo') it works fine.
Any ideas as to how to make this work?

Can gradle android apk project dependencies another apk project's jar task?

I have a project with two modules:
first one HostProject
second one SubProject
LibProject is a android apk project but has a jar task to make a jar from the code.
jar task:
task sourcesJar(type: Jar) {
from 'build/intermediates/classes/debug'
archiveName 'SubProject.jar'
}
In HostProject I want to use libproject's code by the jar file. Is there someway easy to add dependency?
HostProject build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
****compile project(':LibProject')****
}
gradle show error: resolves to an APK archive which is not supported as a compilation dependency
can I use the dependencies in HostProject's build.gradle without add new task?

what is the root of the path in gradle when using configuration injection?

I am using configuration injection for gradle and have something like this
subprojects {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'webserver/play-1.2.4/framework', include: '*.jar')
}
}
My directory structure is
project
subproject1
subrpoject2
I run the command
gradle subproject1:dependencies and it is EMPTY :( :(
soooo, what should the relative file paths be so that this works????
thanks,
Dean
Currently, the dependencies task only shows repository dependencies. You can print the files that a configuration gets resolved to with:
task log << {
configurations.compile.each { println it }
}
Also, it turns out that the confgiuration injection, the paths are relative to the subproject so maybe ../ would be needed in some cases I guess.

Resources