Confused with Gradle Dependencies - gradle

I am trying to add my dependencies to Gradle Dependencies library in eclipse, and when I run this, it downloads these dependencies, however my other dependencies are in the Gradle Dependencies folder under Gradle Project in eclipse but this one is not. Please help, I just need to add a Gradle Dependency in eclipse.
repositories {
mavenCentral()
maven {
url "http://clojars.org/repo"
}
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile "org.clojars.jmeeks:jfugue-with-musicxml:4.0.3"
testCompile group: 'junit', name: 'junit', version: '4.+'
}

You should tell to gradle about your local repository adding mavenLocal() first in repositories section. Using your current configuration you are telling to gradle that everything is stored in mavenCentral or the custom repo.

Related

IntelliJ doesn't recognize dependencies downloaded via Gradle

I'm having a problem importing dependencies into my code in IntelliJ
My build.gradle file is as follows:
plugins {
id 'groovy'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:2.3.11'
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
}
test {
useJUnitPlatform()
}
Gradle doesn't seem to struggle to find and download the dependencies as I can find them locally in
C:\Users%USER%.gradle\caches\modules-2\files-2.1\com.squareup.retrofit2\retrofit\2.9.0
I've updated IntelliJ to make sure it's up-to-date and have also tried invalidating cache and restarting several times. I'm out of ideas at this point, any help would be kind.

Adding sources for IntelliJ plugin via Gradle

I've setup an IntelliJ plugin using Gradle. My build.gradle file contains:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.3.12'
}
//...
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
intellij {
version '2018.2.4'
plugins 'git4idea'
}
Is there any way how I can include/download the sources of the Git4Idea plugin to the project so that they are available automatically?
No, you can't. It'a bug. I filed it here on the plugin's issue tracker.

How to setup Spek Framework

I've checked the docs:
https://spekframework.org/migration/#maven-coordinates
I wanted to try out version 2.x.x, so I added in build.gradle:
testImplementation ("org.spekframework.spek2:spek-dsl-jvm:2.0.0")
testRuntimeOnly ('org.spekframework.spek2:spek-runner-junit5')
But Gradle is unable to find that 2.x.x library in Maven Central:
https://search.maven.org/search?q=spek-dsl-jvm
What should I do? Is there a special repo?
try to configure your repositories with:
maven { url 'https://oss.jfrog.org/artifactory/libs-snapshot'}
Your dependency should be as follows:
dependency "org.spekframework.spek2:spek-dsl-jvm:$spekVersion"
where spekVersion = "2.0.0-SNAPSHOT"
You should add the following maven repo to your build file:
repositories {
jcenter()
}
Then for the dependencies:
testCompile group: 'org.spekframework.spek2', name: 'spek-dsl-jvm', version: '2.0.0-rc.1'
testCompile group: 'org.spekframework.spek2', name: 'spek-runner-junit5', version: '2.0.0-rc.1'
You could also checkout https://github.com/spekframework/spek-multiplatform-example for more info.

Gradle dependency for compile time only and test

I am basically looking for a way to mimic the maven dependency provided. I am building a jar (an extension to a db driver), which depends on another jar (the db driver), but I do not want to include that jar.
I am able to use compileOnly to achieve that, however now the tests won't run or compile as the required jar is not included in tests.
I tried through the list of available dependencies like testCompile, however I could not find one that makes the jar available at compile time and when the tests run and compile.
How would I include that jar properly?
Edit: As requested, the build.gradle file:
group 'com.mygroup'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compileOnly "org.mongodb:mongodb-driver:3.3.0"
testCompile "org.mongodb:mongodb-driver:3.3.0"
}
Listing the dependency twice does work, however obviously is not a very nice solution
You can extend your testCompile configuration from the compileOnly configuration:
configurations {
testCompile.extendsFrom compileOnly
}
I use the following;
sourceSets {
// Make the compileOnly dependencies available when compiling/running tests
test.compileClasspath += configurations.compileOnly
test.runtimeClasspath += configurations.compileOnly
}
which is a line longer than the answer from tynn, but makes the intent clearer IMHO,

Error building project while excluding transitive dependency in build.gradle file

I am creating a multi module project with Spring Boot for deploying my application and using gradle as my build tool.
Now, I am creating independent deployments for some modules in the project. Some of the project requires Embedded tomcat and some do not. All the common dependencies have been put on a common project and all other modules are dependent on this common project.
Most of the other deployment modules require an embedded tomcat application server and other web components (provided by org.springframework.boot', name: 'spring-boot-starter-web) so this has been included in the build.gradle for common project
Here is the build.gradle for common project:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion
Now, one of the other modules which is going to be deployed independently does not require this embedded tomcat and other mvc jars which comes with including spring-boot-starter-web but requires the other transitive dependencies from common project. As such, I want to exclude the transitive dependency for
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
I am doing it like this in the build.gradle other project
dependencies {
compile project(':common') {
exclude group 'org.springframework.boot', module:'spring-boot-starter-web'
}
}
But while building it is throwing this error:
startup failed: build file
'/Users/user1/Documents/repo/storm/build.gradle': 30: expecting '}',
found ',' # line 30, column 44.
oup 'org.springframework.boot', module:'
changing it to:
dependencies {
compile project(':common'){
exclude group 'org.springframework.boot:spring-boot-starter-web'
}
}
throws:
Could not find method exclude() for arguments [parent-project name] on
project ':common'.
How can I exclude transitive dependency here?
You need to invoke exclude on compile not on project:
dependencies {
compile(project(':common')) {
exclude group: 'org.springframework.boot', module:'spring-boot-starter-web'
}
}

Resources