2

What can I do to make the following Gradle project build succesfully?

I've build a new project. settings.gradle is:

rootProject.name = 'myproject'

build.gradle is:

group 'mygroup'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.5

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "https://mvnrepository.com/artifact/org.apache.commons/commons-lang3" }
}

dependencies {
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

If I use "Refresh all gradle projects" in the Gradle Tool Window, the Event Log says:

Unindexed remote maven repositories found. [Disable...] The following repositories used in your gradle projects were not indexed yet: https://plugins.gradle.org/m2 https://mvnrepository.com/artifact/org.apache.commons/commons-lang3

Project Structure --> Problems tells me:

Library Gradle: org.apache.commons:commons-lang3:3.6 has broken classes path:   /home/myhome/git/myproject/Could not resolve org.apache.commons:commons-lang3:3.6.

Does anybody know a good instruction website for building gradle projects (other than Getting started with Gradle)? I've also re-setup the project based on these instructions, but I cannot resolve any dependencies either. (auto-import enabled and using a Gradle wrapper)

philburns
  • 310
  • 4
  • 18
  • 3
    The problem seems to be in `maven { url "https://mvnrepository.com/artifact/org.apache.commons/commons-lang3" }` line as repository should specify the root host, not some specific package. – CrazyCoder Aug 07 '17 at 11:26
  • Thanks @CrazyCoder for this information! Please apologize my question, but how is the root host's URL then in this case? (It doesn't seem to be `https://mvnrepository.com/artifact/`. At least, this does not make any difference for the success of my build.) – philburns Aug 07 '17 at 13:32
  • 1
    Why do you need this custom repository anyway? Do you think `mavenCentral` has no `commons-lang3`? – CrazyCoder Aug 07 '17 at 13:51
  • You're right, `mavenCentral` provides commons-lang3 as well. So, if I drop this mvnrepository entry and reduce "repositories" to `mavenCentral()`, the problem remains that I can not resolve any dependency. (`Gradle projects` view shows red underlining "Unable to resolve..." for whichever SourceSet.) – philburns Aug 07 '17 at 14:29
  • Does it build from the command line Gradle outside of IntelliJ IDEA? – CrazyCoder Aug 07 '17 at 14:30
  • $ gradle build --> Starting a Gradle Daemon ... :compileJava ... :processResources ... :classes ... :jar ... :assemble ... :compileTestJava ... :processTestResources ... :testClasses ... :test ... :check ... :build ... BUILD SUCCESSFUL – philburns Aug 07 '17 at 14:55
  • Check [idea.log](https://intellij-support.jetbrains.com/hc/articles/207241085) for errors, if the issue is IntelliJ IDEA specific you should file a bug at https://youtrack.jetbrains.com/issues/IDEA with more details. – CrazyCoder Aug 07 '17 at 14:56
  • idea.log shows: `INFO - util.EmbeddedDistributionPaths - Looking for embedded Maven repo at '/prebuilts/tools/common/offline-m2'` and `INFO - .ExternalSystemRefreshListener - No candidates found`. That's the only build information that somehow might look suspicious to me. I'm not sure whether this is an IntelliJ IDEA specific bug. – philburns Aug 07 '17 at 16:04

2 Answers2

1

Do you have maven installed?

With regards to mavenLocal() Gradle goes and reads ~/.m2/settings.xml to find the info about where is your repo situated, when it can't find any info it is going to assume it's '~/.m2/repository'

Please update the question with the IntelliJ version you are using as versions from 2015, 2016 wasn't that good with Gradle integration yet, if you are using an outdated version, I recommend downloading latest and trying again.


You can use some kind of a workaround for this, in your build.gradle apply plugin: 'idea' and then on the command line do gradle cleanIdea idea - this will delete and recreate your idea files .iws .ipr .iml and recrete the classhpaths and your project should refresh in IntelliJ and work just fine

LazerBanana
  • 6,865
  • 3
  • 28
  • 47
  • 1
    The IntelliJ update hint is useful here. In fact, I had already updated from 2016.3 to 2017.2. After I created another project from scratch, the IDE asked me to leave "Gradle offline mode" - which I never had activated intentionally. I then returned to my former project and resolvements and imports work well now. – philburns Aug 08 '17 at 09:33
1

The problem disappeared after:

  • upgrading from IntelliJ 2016.3 to 2017.2
  • setting up another project from scratch
  • being asked to deactivate "Gradle offline mode" - and answering yes.

Obviously the problem was the "Gradle offline mode" which can be directly deactivated as described in this answer.

philburns
  • 310
  • 4
  • 18