could not resolve all dependencies for configuration ':compile' - gradle

To study Gradle I am using the book Gradle in action.
There was an example of dependency definition.
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
But when I do in console gradle build I've got an error
What is the problem? My whole .gradle file looks like this
apply plugin: 'java'
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}

You did not tell Gradle where to find commons-lang3 library. Easy fix is to add the following to your build script:
repositories {
mavenCentral()
}
Of course you can find this piece of information in documentation - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10608

I was facing this same issue. I fixed it by using local gradle distribution instead of the default gradle wrapper. This is how it goes, make sure that you have Gradle installed and setup(PATH variable).
Open IntelliJ. Goto File->setting->Build, Exec, Deployment->Build tools->Gradle and use local gradle distribution and add your Gradle Home. Apply changes and try to run it now.

Related

Maven Project in IntelliJ, include Gradle Plugin

I'm new to IntelliJ and Gradle
I've got a Maven Project with a lot of dependencies which works on it's own.
Now I should use the libraries from that Project and create a Plugin for IntelliJ in Gradle.
I tried various ways to add the dependencies in the IntelliJ Module Settings, which allowed me to use the needed classes to write my code and build it. However, when I tried to start the plugin, it couldn't find the classes anymore.
I think I need to specify these in the build.gradle but I don't understand exactly how, as all the ways I tried didn't worked.
build.gradle:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.5'
}
group 'com.ast.devmate.intellij'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
**compile 'com.ast.devmate.intellij:root:1.0.0-SNAPSHOT'**
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2019.1'
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
gets me this:
Could not find com.ast.devmate.intellij:root:1.0.0-SNAPSHOT.
without the line marked with ** I got a lot of
error: package foo does not exist
import foo;
It looks like you're trying to access a custom library using Gradle. You will probably need to use a file dependency: How to add local .jar file dependency to build.gradle file?

Sonarqube gradle analyzing project, task not found in root project

Analysing project with this command
.\gradlew sonarqube \ -Dsonar.host.url=http://my.url \ -Dsonar.login=login --stacktrace
Getting this error
org.gradle.execution.TaskSelectionException: Task '\' not found in root project 'JavaLint'
And here is my gradle file
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'eclipse'
archivesBaseName = 'JavaLint'
version = '0.1-SNAPSHOT'
mainClassName = 'Main'
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'com.test.Run'
}
}
sourceSets {
main {
java {
srcDirs 'src'
}
}
}
dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.2'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'log4j', name: 'log4j', version: '1.2.16'
}
Stack trace
I don't understand what am i supposed to do with it.
It looks like you're using cmder (it's so beautiful) which means you're on Windows. For Windows you'll want to provide the arguments to gradle as follows
./gradlew sonarqube -D "sonar.projectKey=<your_project_name>" -D "sonar.host.url=http://localhost:9000" -D "sonar.login=<your_project_token>"
Thanks to the accepted answer by #ka whosyour above,I got my answer too.
Ok let me mention the details of how I was doing for an Android project in Android Studio and what I figured out after my research.
From the command generated by the Sonar Dashbaord, it is
./gradlew sonarqube \-Dsonar.projectKey=LetsGo \-Dsonar.host.url=http://localhost:9000 \-Dsonar.login=53689e9ceab73b3e8a76007d7953af3e9e2b2052
But, for Windows machine it should actually be:
gradlew sonarqube -Dsonar.projectKey=LetsGo -Dsonar.host.url=http://localhost:9000 -Dsonar.login=53689e9ceab73b3e8a76007d7953af3e9e2b2052
This worked like a charm for me.
Notice the Backwards slashes \ which are not needed on the windows machine.
Also, ./gradlew works in mac and gradlew on windows
Make sure first the directory contains gradle.build.
The command for windows :
./gradlew sonarqube -D "sonar.projectKey=your_sonarqube_key" -D "sonar.host.url=http://localhost:9000" -D "sonar.login=your_sonarqube_token"
This has worked for me as expected.
Use it like that in windows Terminal:
.\gradlew sonarqube -Dsonar.host.url=http://my.url -Dsonar.login=login --stacktrace
After that ,you will find the project already in the SonarQube server.

Gradle properties in 2.6 vs 2.7

If I specify in 'build.gradle' that belongs to the root:
allprojects {
version="1.0-SNAPSHOT"
}
Then I want to use the same version property in a subproject like that:
dependencies {
compile group: 'com.myproject.module', name: 'first', version: allprojects.version
}
In Gradle 2.6: it will put '[1.0-SNAPSHOT]'
In Gradle 2.7: it will be '1.0-SNAPSHOT' without brackets
What can be the reason for that? Is that due to some gradle issues in 2.6? In gradle 2.2.1 - it also works fine. Maybe you could recommend some best practices here?
answer can be found here (I posted the same question on gradle forum): https://discuss.gradle.org/t/gradle-properties-in-2-6-vs-2-7/11919

Gradle: dependencies inside build.gradle vs. inside buildScript()

Inside my module build script (build.gradle) I can set dependencies:
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
}
Gradle Example 8.2
I can also use buildscript() method inside the build script and set dependencies:
If your build script needs to use external libraries, you can add them
to the script's classpath in the build script itself. You do this
using the buildscript() method, passing in a closure which declares
the build script classpath.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
}
}
Gradle Example 59.6
My question, are these the same? Is there any difference between these two ways of setting dependencies for the build script?
There is a big difference. The former declares (compile) dependencies of your code; the latter declares dependencies of the build script itself (i.e. it allows to use commons-codec right in the build script).

Process a subset of my dependencies in Gradle

I have a simple project where I'd like to unjar a subset of my dependencies and pack them into the output jar.
I have the two configurations:
configurations {
embed
all
}
dependencies {
embed group: 'commons-collections', name: 'commons-collections', version: '3.2'
...
all embed
all group: 'something-not-embeddable', name: 'dontembed'
compile all
}
According to http://www.gradle.org/docs/current/userguide/dependency_management.html 50.5 Working with Dependencies section's example it should work.
In a later section of my build, I want to unjar the embed jars and use them as source for jar.
My problem is that the gradle output says:
> Could not find method all() for arguments [configuration ':embed'] on root project 'myproject'.
Can you tell me why my approach is not working and how could I fix it?
Lol, looks like I chose a bad configuration name, works with alldeps instead of all

Resources