Gradle local dependencies are not visible - java

In my project I use some local dependencies:
dependencies {
compile files('lib/mylib.jar')
}
Why when I call gradle dependencies I can't see this library as a dependency? Command gradle dependencies --configuration compile returns this:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
No dependencies
Dependencies downloaded from repository (maven/ivy) are visible. For example:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:14.0.1'
}
will show:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Compile classpath for source set 'main'.
\--- com.google.guava:guava:14.0.1
BUILD SUCCESSFUL
I should also add that dependencies are not shown but project compiles properly.

Gradle documentation on file dependency explains
File dependencies are not included in the published dependency descriptor for your project. However, file dependencies are included in transitive project dependencies within the same build. This means they cannot be used outside the current build, but they can be used with the same build.

Use api(name: 'mylib', ext: 'jar') as a workaround.

Related

Gradle : Dependency not getting added to classpath

I have added below dependency in build.gradle file. Eclipse plugin is added in build.gradle.
testCompile 'io.dropwizard:dropwizard-testing:1.2.0'
Once I run gradle eclipse command all the compile dependencies are getting added in classpath but testcompile dependencies are not getting added in classpath.
But testCompile 'io.dropwizard:dropwizard-testing:1.2.0' also has transitive dependencies like mockito. Therefore whenever I am trying to use mockito in my Junit, those are not getting compiled.
I am not sure what is the problem none of the transitive dependency of io.dropwizard:dropwizard-testing:1.2.0 is available
Looking at the dropwizard-testing dependencies here I can't see mockito in the compile scoped dependencies. It's in the test scoped dependencies but that's irrelevant, test scoped dependencies are private to that project and don't become transitive dependencies when the jar is included in another project.

Gradle project dependency error in Jenkins

I have a project structure similar to
//Directory structure
Root Folder/
projectA/
build.gradle
projectB/
build.gradle
properties.gradle
Now, project B is dependent on project A
The settings.gradle and build.gradle for Project B is as follows
settings.gradle
include ':ProjectA'
project(':ProjectA').projectDir = new File(settingsDir, '../ProjectA')
build.gradle
dependencies{
compile project(':ProjectA')
}
When I try to build project B on my local machine (Gradle version 3.2) it builds successfully and everything looks good.
When i try to build the same project in jenkins (same gradle version as my local), i am getting the error
Caused by: org.gradle.api.artifacts.UnknownConfigurationException: Configuration with name 'default' not found.
It looks like in jenkins, it is not able figure out the relative path.
How do I solve this?
Is there a way in jenkins I can ignore the dependency from gradle and use the pre build to compile ProjectA and put that in the classpath? If so how can we do it?
I was able to solve this by adding a jenkins property which I check in the build file
if (project.hasProperty('jenkins')) {
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
} else {
dependencies {
compile project(':ProjectA')
}
}
So when we build it locally, since we are not passing the property it is able to compile ProjectA. In Jenkins, the build job, in the gradle command I am passing the following -Pjenkins clean build. This goes to the if condition and pulls the jar from projectA and puts that in the lib directory.
This has solved the problem for me, let me know if there are better solutions for it

How to add gradle library dependency to a codenameone project

Normally in android I can just edit the build.gradle file and place my compile dependencies like this:
dependencies {
compile 'com.android.support:support-v4:23.+'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-base:8.3.0'
}
How can I add a compile dependency in a codenameone project?
The generated project utilizes the jcenter() repository.
In order to add a compile dependency you will need to use the 'gradleDependencies' build hint, for example:
gradleDependencies=" compile 'com.facebook.android:facebook-android-sdk:4.7.0'\n"

Why doesn't gradle return dependencies for another projects?

I have the following build script (webapp:build.gradle):
apply plugin: 'java'
dependencies {
project(':api')
}
When I run gradle dependencies webapp:dependencies in command line I get:
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
:webapp:dependencies
------------------------------------------------------------
Project :webapp
------------------------------------------------------------
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
No dependencies
default - Configuration for default artifacts.
No dependencies
runtime - Runtime classpath for source set 'main'.
No dependencies
testCompile - Compile classpath for source set 'test'.
No dependencies
testRuntime - Runtime classpath for source set 'test'.
No dependencies
There was nothing to be said about dependency from api project. Why? What's wrong?
Because You haven't specified configuration name for this dependency. It should be e.g.:
dependencies {
compile project(':api')
}
webapp/build.gradle
apply plugin: 'java'
dependencies {
compile project(':api')
}
webapp/settings.gradle
include 'api'
webapp/api/build.gradle
apply plugin: 'java'

Gradle dependencies local jar file

I have problem with include local jar file.
I have two projects:
ProjectA
ProjectB
--libs
----jgrapht-jdk1.6.jar
My build file include (This is the part that concerns projectB):
project(':ProjectB') {
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
compileOnly
}
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
dependencies {
compileOnly files('libs/jgrapht-jdk1.6.jar')
compile 'org.simpleframework:simple-xml:2.7#jar'
}}
I run command gradlew -q dependencies and see result
Project :ProjectB
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
\--- org.simpleframework:simple-xml:2.7
compileOnly
No dependencies
default - Configuration for default artifacts.
\--- org.simpleframework:simple-xml:2.7
runtime - Runtime classpath for source set 'main'.
\--- org.simpleframework:simple-xml:2.7
testCompile - Compile classpath for source set 'test'.
\--- org.simpleframework:simple-xml:2.7
testRuntime - Runtime classpath for source set 'test'.
\--- org.simpleframework:simple-xml:2.7
Line compile 'org.simpleframework:simple-xml:2.7#jar' - working fine,
but line compileOnly files('libs/jgrapht-jdk1.6.jar') don't work.
I use gradle 1.8, Windows 7 x64
Tell me please where I made a mistake.
It's a known limitation that file dependencies aren't currently shown by gradle dependencies. They nevertheless work (if the paths are right).

Categories

Resources