could not find com.android.tools.build.gradle:4.6 - gradle

Im trying to run an app I wrote in a diffrent computer and I get this error:
Error:Could not find com.android.tools.build:gradle:4.6.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/tools/build/gradle/4.6/gradle-4.6.pom
file:/C:/Program Files/Android/Android Studio1/gradle/m2repository/com/android/tools/build/gradle/4.6/gradle-4.6.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/4.6/gradle-4.6.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/4.6/gradle-4.6.jar
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.6/gradle-4.6.pom
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.6/gradle-4.6.jar
Required by:
project :
Open File
I've Updated anything I could think of but nothing works.
Thank you!

Please give more contextual information.
Since I lack these information, I can only make a guess: did you specify the new google() maven repository in your project build.gradle file?
buildscript {
repositories {
...
google() // this replace https://maven.google.com
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
If you need google() repository in your module(s), you can also add this in your project build.gradle file
allprojects {
repositories {
...
google()
...
}
}

here is the latest, use this:
classpath 'com.android.tools.build:gradle:3.1.0'
https://developer.android.com/studio/releases/gradle-plugin.html

buildscript {
repositories {
jcenter()
maven { url "https://maven.google.com" } // here... try adding this line
}

Related

Unable to apply plugin in gradle init script

Here is my gradle init script.
initscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
}
}
allprojects {
apply(plugin="java")
apply(plugin="application")
apply(plugin="org.springframework.boot.gradle.plugin.SpringBootPlugin")
repositories {
gradlePluginPortal()
mavenCentral()
}
}
However, I am getting Plugin with id 'org.springframework.boot.gradle.plugin.SpringBootPlugin' not found. error.
I have tried the solutions from the following questions but none of them solves the problem.
Add Android plugin to gradle init script
I have found my solution after googling around.
In order to apply plugins in gradle init script that is written in kotlin DSL,
one has to use the following
initscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
}
}
allprojects {
apply(plugin="java")
apply(plugin="application")
apply<org.springframework.boot.gradle.plugin.SpringBootPlugin>()
repositories {
gradlePluginPortal()
mavenCentral()
}
}
In order to apply third party plugins in the init script, one has to use the form apply<path.to.classname>()

Get a nexus artifact as a dependency in gradle?

I have the following nexus artifact :
com/companyName/my-awesome-util/0.0.0/my-awesome-util-0.0.0.jar
and I just have absolutely no clue how to get it within my gradle build file. I have googled it, followed examples, and I just cannot get it to work. I come from the maven world, and I just need to get this one thing to work so that I can at least understand what the hell I need to do in future.
First, add a repository in your build.gradle:
repositories {
maven { url 'http://nexus.acme.corp' }
}
Then, refer to that artifact:
dependencies {
compile 'com.companyName:my-awesome-util:0.0.0'
}
That's basically it!
If your Nexus is secured by credentials, use this snippet:
repositories {
maven {
url 'http://nexus.acme.corp'
credentials {
username = 'darth'
password = 'vader'
}
}
}
Add some Nexus maven2 proxy repositories with the following remote storage urls each:
https://jcenter.bintray.com/
https://repo1.maven.org/maven2/
https://maven.google.com/ # used to download com.android.tools.build:gradle
https://plugins.gradle.org/m2/
And then add them into a meven2 group repository, named such as maven-public:
And then use this group repo's url in your file build.gradle:
buildscript {
repositories {
google()
mavenCentral()
// jcenter()
maven {
// url "https://plugins.gradle.org/m2/"
url "https://YOUR-NEXUS-URL.com/repository/maven-public/"
}
}
......
........
......
allprojects {
repositories {
buildscript {
apply from: 'dependencies.gradle'
repositories {
google()
mavenCentral()
// jcenter()
maven {
// url "https://plugins.gradle.org/m2/"
url "https://YOUR-NEXUS-URL.com/repository/maven-public/"
}
}
}
}

Import buildscripts in gradle

I am pretty new with gradle, I want to include a plugin globally, and I don't know how.
In my project(wish I DO NOT OWN), there are multiple build.gradle, and there is a commons.gradle folder. In there is created a script like this
myscript.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1"
}
}
Then in of the build.gradle I have this:
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
apply from: "$path-to/myscript.gradle", to: buildscript
}
apply plugin: "com.github.hierynomus.license"
but I keep getting a Plugin with id com.github.hierynomus.license" not found. I am using Gradle 3.1. any help or hint would greatly help.
Thanks
I was able to make this work by doing the following:
myScript.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1"
}
}
then in the build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
apply from: "$path-to/myScript.gradle", to: buildscript
}
plugins{id "com.github.hierynomus.license" version "0.13.1"}
apply plugin: "com.github.hierynomus.license"
I was not able to find anything online, so I hope this will help someone one day.
ps: Sorry for my bad English

Gradle Custom buildScriptRepository methods

I would like to make a custom buildScript repository method so I can easily reference our internal maven repo. Right now I'm required to declare a maven block everywhere we use our plugin.
Here is the current setup
buildscript {
repositories {
jcenter()
maven { url 'http://myNexus:8081/nexus/content/repositories/My-Release' }
}
dependencies {
classpath 'com.example.plugin:my-plugin:1+'
}
}
What I would like to do is something like this
buildscript {
repositories {
jcenter()
myReleaseRepo()
}
dependencies {
classpath 'com.example.plugin:my-plugin:1+'
}
}
How can I make a method available to create a repository anywhere we may use the plugin in the future?
Another solution is to add custom methods on RepositoryHandler using some Groovy goodness. Just chuck this in ~/.gradle/init.gradle
RepositoryHandler.metaClass.myReleaseRepo = {
delegate.maven {
name 'myReleaseRepo'
url 'http://myNexus:8081/nexus/content/repositories/My-Release'
}
}
After that, you can use it just as you described:
buildscript {
repositories {
myReleaseRepo()
}
}
Metaclasses in Groovy are just great. The delegate in this case is pretty much like the javascript this. This code is essentially using the RepositoryHandler instance (delegate keyword) and just calling repositoryHandlerInstance.maven(name, url).
It is possible to add a repo to an init script which would then apply to all gradle invocations that use the init script - without having to individually declare your maven repo in each build.gradle.
Solution 1:
Partial solution, does not do exactly what you're asking for. In init.gradle:
allprojects{
buildscript{
repositories{
maven{ url 'http://myNexus:8081/nexus/content/repositories/My-Release' }
}
}
}
Then your build.gradle can skip buildscript repo declaration entirely:
buildscript {
dependencies {
classpath 'com.example.plugin:my-plugin:1+'
}
}
Solution 2:
In fact, you can even move your buildscript classpath declaration to init and have the plugin apply to all projects that use the init script:
beefier init.gradle
allprojects{
buildscript{
repositories{
maven{ url 'http://myNexus:8081/nexus/content/repositories/My-Release' }
}
dependencies {
classpath 'com.example.plugin:my-plugin:1+'
}
}
}
gives you a lighter build.gradle
apply plugin: 'my-plugin'
I tried to, but apparently you cannot move the apply line to init.gradle as well. see this defect.
Solution 3:
I retract what I said in the comment above, I figured out how to do exactly what you're asking for. Apparently you can create extensions for the buildscript block using the initscript. However I still prefer solution2, because it gives you a cleaner build.gradle.
To create a buildscript extension, in your init.gradle:
class customRepos {
def buildscript
customRepos(buildscript) {
this.buildscript = buildscript
}
void addMyRepo() {
buildscript.repositories {
maven{ url 'http://myNexus:8081/nexus/content/repositories/My-Release' }
}
}
}
allprojects {
extensions.create('myRepo', customRepos, buildscript)
}
which then allows you to do this in your build.gradle
buildscript{
myRepo.addMyRepo()
dependencies {
classpath 'com.example.plugin:my-plugin:1+'
}
}
apply plugin: 'my-plugin'

Gradle Multiple Maven Repo

I added a dependency to my build.gradle: spring-data-neo4j
It requires neo4j-cypher-dsl-2.0.1.jar/pom, which is only located in the repo: https://repo1.maven.org/maven2/.
However as per the output below gradle never looks at this repo for the artifact. How can I get gradle to search this repo as well.
//build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url "https://repo1.maven.org/maven2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE")
}
}
gradle build:
FAILURE: Build failed with an exception.
What went wrong: Could not resolve all dependencies for configuration ':compile'.
Could not find org.neo4j:neo4j-cypher-dsl:2.0.1. Searched in the following locations:
https://repo1.maven.org/maven2/org/neo4j/neo4j-cypher-dsl/2.0.1/neo4j-cypher-dsl-2.0.1.pom
https://repo1.maven.org/maven2/org/neo4j/neo4j-cypher-dsl/2.0.1/neo4j-cypher-dsl-2.0.1.jar Required by:
**:feedserver:1.0.0 > org.springframework.data:spring-data-neo4j:3.2.2.RELEASE**
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Edit:---------------------------------------
Sorry I accidently posted the incorrect build.gradle contents above, which has repeated maven central locations. This is my actual build.gradle file...When I build using these settings I still get the error above:
buildscript {
repositories {
mavenCentral()
maven {
url "http://m2.neo4j.org/content/repositories/releases/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE")
}
}
neo4j-cypher-dsl is not in Maven central. It is available in Neo4j repository you have to add another repo something like this:
repositories {
maven {
url "http://m2.neo4j.org/content/repositories/releases/"
}
}
NOTE is not necessary to use another maven ponting to maven central using mavenCentral() is enough
EDIT 1
repositories section in buildscript just works for dependencies inside. In this case for spring-boot-gradle-plugin
buildscript {
ext {
springBootVersion = '1.1.9.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
In your case you want to add another dependencies for your project. So you need to add another repositories section out of buildscript
repositories {
mavenLocal()
mavenCentral()
maven {
url "http://m2.neo4j.org/content/repositories/releases/"
}
}

Resources