question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot resolve external dependency com.google.googlejavaformat:google-java-format:1.3

See original GitHub issue

Recently I have upgraded to spotless 3.4.0. Gradle 3.5 and Java 1.8 My spotless config

buildscript {
  repositories {
    mavenCentral()
    maven { url 'https://plugins.gradle.org/m2/' }
  }
  dependencies {
    classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.4.0'
    classpath 'com.google.googlejavaformat:google-java-format:1.3'
  }
}

apply plugin: com.diffplug.gradle.spotless.SpotlessPlugin

spotless {
  java {
    googleJavaFormat('1.3')
    custom 'Lambda fix', { it.replace('} )', '})').replace('} ,', '},') }
    importOrder(['java', 'javax', 'org', 'com'])
    trimTrailingWhitespace()
    removeUnusedImports()
  }
  format 'misc', {
    target '**/.gitignore', '**/*.gradle', '**/*.md', '**/*.sh'
    indentWithSpaces(2)
    trimTrailingWhitespace()
    endWithNewline()
  }
}

I am getting following error.

:spotlessJava
You probably need to add a repository containing the '[com.google.googlejavaformat:google-java-format:1.3]' artifact, e.g.: 'buildscript { repositories { mavenCentral() }}'
org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':detachedConfiguration1'.
        at org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.rethrowFailure(DefaultLenientConfiguration.java:192)
        at 
 (tons more)

If I downgrade to 3.0.0 its just working fine for the same config.


EDIT by @nedtwigg: this is a long thread, but the resolution was that the buildscript block above must appear in build.gradle, it’s not enough for it to be appear in a separate file, such as spotless.gradle, which gets included.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
fvghcommented, Jul 4, 2017

Sorry Ned, I am unsure now what your final word is. In your previous comment you stated that security concerns should not block for my proposal. And you mentioned CI. My experience with CI was actually the key point why I think my proposal is not a hack. My proxy config looks like this:

allprojects {
	buildscript {
	    repositories {
		maven {
			url "http://<ip>:<port>/apache-archiva/repository/internal/"
		}
	    }
	}		
	repositories {
		maven {
			url "http://<ip>:<port>/apache-archiva/repository/internal/"
		}
	}
}

This is in my opinion how gradle wants a proxy to be configured. If the proxy can can not resolve the extensions and direct access of Maven Central is denied, than you get an error like you do now. I had the problem that my proxy forwards request to Maven Central. So when #99 was solved, I needed no changes in my build scripts. But when I committed the JUnit changes, JUnit Travis failed. This would not have happen with my proposed solution. When I said that disallowing access to all Maven Central versions (via proxy or not), I meant ‘rare’ in the sense that it only affect less than 5% of the users. 95% of the users would be able just to use spotless without any further configuration, regardless whether they use multi-project, or configured spotless in a dedicated gradle file. Just let me now what the final solution shall be.

1reaction
fvghcommented, Jun 12, 2017

rootProject is possible, but still does not help (at least according to my understanding of the Gradle Doc) if you use apply plugin and have your spotless config in a separate script, which I think is quite common scenario. Let me look for the right hook and the solution will cover (I’ll add tests 😄 ) both scenarios.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keep getting Cannot resolve external dependency com ...
I have an app that I have created. The app up until now has been able to login existing users and register new...
Read more >
Cannot resolve external dependency com.android.tools.build ...
I do an update in my android studio, i have the following error. I know that the problem in build.gradle, how can i...
Read more >
Re: Cannot resolve external maven dependencies with gradle ...
I'm not able to resolve external dependencies using gradle. I've created a brand new project, and edited the gradle.build file to be as...
Read more >
Does the lifecycle of a build differ when called by buildship to ...
in this situation, buildship fails to import dependencies (a long list of “could not resolve” errors) whereas running a gradle task from eclipse...
Read more >
Different Ways to fix Cannot resolve symbol ... - GeeksforGeeks
gradle(Module:app) file and in the dependencies section the appcompat one, you should see something like compile 'com.android.support:appcompat- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found