3

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)

8
  • 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. Commented Aug 7, 2017 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.) Commented Aug 7, 2017 at 13:32
  • 1
    Why do you need this custom repository anyway? Do you think mavenCentral has no commons-lang3? Commented Aug 7, 2017 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.) Commented Aug 7, 2017 at 14:29
  • Does it build from the command line Gradle outside of IntelliJ IDEA? Commented Aug 7, 2017 at 14:30

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.