I want to create an executable Jar for Spring Boot using gradle in an offline environment.
There is an error.
Please tell me the solution.
■cmd
C: / ~ / ~ / demo gradlew bootJar --offline --stacktrace
FAILURE: Build failed with an excetion.
What went wrong:
Task 'bootJar' not found in root project 'demo'.
Exception is:
org.gradle.execution. TaskSelectionException: Task 'bootJar' not found in root project 'demo'.
......
■build.gradle
plugins {
// id 'org.springframework.boot' version '2.4.2'
// id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
■gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
■version
SpringBoot:2.4.2
gradle:6.6.1
The bootJar task comes from the Spring Boot Gradle plugin (org.springframework.boot). You've removed the plugin from the project therefore the bootJar task never gets created.
Gradle is smart enough to cache various parts of the build including dependencies and plugins. However, since you are getting that error, the Spring Boot plugin is not cached therefore you must go online temporarily in order for the plugin to be downloaded and cached.
If you're not able to temporarily go online, then for the bootJar task specifically, you must reimplement yourself in your project: https://github.com/spring-projects/spring-boot/blob/2.4.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:
Error:(1, 0) Plugin with id 'com.android.application' not found
C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.bob.helloagain6"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Updated Answer (Dec. 2, 2020)
Latest Gradle: 6.5
Version check:
./gradlew -v
How to update:
Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
Update: ./gradlew wrapper
Latest Android Gradle Plugin: 4.1.0
If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.
buildscript {
repositories {
google() // For Gradle 4.0+
maven { url 'https://maven.google.com' } // For Gradle < 4.0
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.
Original Answer
I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.
The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.
This can happen if you miss adding the Top-level build file.
Just add build.gradle to top level.
It should look like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.xx.y'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.
Root-gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:x.x.x'
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
In the project level build.gradle file, I have replaced this line
classpath 'com.android.tools.build:gradle:3.6.3'
with this one
classpath 'com.google.gms:google-services:4.3.3'
After adding both of those lines, and syncing, everything became fine.
Hope this will help someone.
I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)
This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.
The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.
Finally, I figured out that it was my following mistake:
I tried importing a specific Application alone instead of importing the application along with dependent library projects.
The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)
I found the problem after one hour struggling with this error message:
I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.
Renaming it to build.gradle resolved the issue!
I still got the error
Could not find com.android.tools.build:gradle:3.0.0.
Problem: jcenter() did not have the required libs
Solution: add google() as repo
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.0"
}
}
I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result.
Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.
Go to your grade file where you can see this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
And change classpath to this:
buildscript {
repositories {
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.
However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.
So, you should just avoid the duplication or conflict.
For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.
This issue happened when I accidently renamed the line
apply plugin: 'com.android.application'
on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.
[FOR FLUTTER] go to your build Gradle then check if you have three paths
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
I somehow removed the android tools classpath and was getting the error.
This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.
If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html
Then open "as existing project" in Visual Studio
Gradle is very finicky about this.
I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:
//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new
I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.
In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:
./gradlew --refresh-dependencies
This caused the newer version of gradle to be re-downloaded and the error no longer occurs.
Check the spelling, mine was 'com.android.aplication'
This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.
i had similar problem and i did following things to resolve it.
i referred to https://developer.android.com/studio/build
and copy / pasted these following lines before apply plugin lines
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
module app build.gradle file
apply plugin: 'com.android.application'
model{
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig.with {
applicationId "com.iamsafe"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
debug {
minifyEnabled = false
useProguard = true
proguardFiles.add(file('proguard-rules.txt'))
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.2'
compile files('libs/asmack-android-8-0.8.10.jar')
compile files('libs/commons-io-2.0.1.jar')
compile files('libs/httpclient-osgi-4.2.1-sources.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.1.2.jar')
}
project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.10'
}
}
allprojects {
repositories {
jcenter()
}
}
In this case of issues check below code
dependencies {
classpath 'com.android.tools.build:gradle:**1.5.0**'
}
and gradle-wrapper.properties inside your project directory check below disctributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
If these are not compatible with each other then you end up in this issue.
For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
If you work on Windows , you must start Android Studio name by Administrator.
It solved my problem
Just make sure you put the http and https proxy correctly when you create the app
I receiving this error after tried solving the google() error following the link [StackOverflow Link] (Error:(6, 0) Gradle DSL method not found: 'google()')
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The code for gradle-wrapper.properties
#Mon Jun 19 10:50:31 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
My Android studio version is 3.3.2
The following is the full error appeared. Little help would be highly useful.
Gradle DSL method not found: 'ooapply()'
Possible causes:
The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.3.2 and sync project
The project 'MyProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
I was unable to proceed ...
It looks like a problem in another build.gradle file.
The file you have attached is probably a Project-level build.gradle.
I guess that the problem is inside Module-level build.gradle file. Open this file and replace ooapply with apply.
When compiling and building my android app, an error as shown below keeps occurring. I have been using this stack overflow answer to solve the error and exclude the duplicate files.
Here is the error I get when I try to build my project.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt
File1: /Users/tomfinet/.gradle/caches/modules-2/files-2.1/com.google.appengine/appengine-api-1.0-sdk/1.9.28/e92c18272b555027d9ec666e7a89162f10638314/appengine-api-1.0-sdk-1.9.28.jar
File2: /Users/tomfinet/.gradle/caches/modules-2/files-2.1/com.google.appengine/appengine-endpoints/1.9.28/bf2e8a74bd28e388b3487fc78a0c7adfa592fd5d/appengine-endpoints-1.9.28.jar
When I run the terminal command ./gradlew dependencies as instructed in the stack overflow answer, I am supposed to see the entire dependency tree for my project.
However all I see is this:
Downloading https://services.gradle.org/distributions/gradle-2.10-all.zip
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Unzipping /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10-all.zip to /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst
Set executable permissions for: /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10/bin/gradle
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.
Incremental java compilation is an incubating feature.
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
BUILD SUCCESSFUL
Total time: 53.171 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Here is my gradle file for the backend:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.28'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.28'
compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.0.3'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
So how do I resolve this conflict between the dependencies? I am pretty sure I have to exclude the conflicting files. But how do I find the files that are causing this?
I want to install android library project to local maven repository.
Here is build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
apply plugin: 'maven'
version = "1.0.0-SNAPSHOT"
group = "com.example"
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
}
When I run:
gradle install -i
it gets stuck here:
Executing task ':project:installTest' due to:
Task has not declared any outputs.
Starting process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''. Working directory: D:\Projects\java\....... Command: d:\android-sdk-windows\platform-tools\adb.exe install -r D:\Projects\java\.......\build\apk\project.apk
An attempt to initialize for well behaving parent process finished.
Successfully started process 'command 'd:\android-sdk-windows\platform-tools\adb.exe''
> Building > :project:installTest
So first thing I noticed is that it's trying for some odd reason to deploy it on a device as APK.
Am I doing something wrong or is it just android-library plugin not compatible with maven plugin?
Edit: Please refer to the github page (https://github.com/dcendents/android-maven-gradle-plugin) for the latest instructions and find the correct version to use. The original instructions are not suitable anymore with the latest gradle release.
Original Post:
I've modified the maven plugin to be compatible with android library projects. See the project on github: https://github.com/dcendents/android-maven-gradle-plugin
Configure your android library projects to use it:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
apply plugin: 'android-library'
apply plugin: 'android-maven'
Then you should be able to install aar into your local maven repository using the install task.
Hope this helps, if you find issues with the plugin please let me know on github and I'll fix it.
Elaborating on CyclingSir's answer, I propose to add a separate "installArchives" task. This should also take care of picking up your custom artifacts (e.g. sources).
apply plugin: 'maven'
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: repositories.mavenLocal().url
}
}
}
Note that with Gradle Android plugin v0.5.5, gradle install still tries to install something on a device.
There's an easier solution if you don't want to use a custom plugin. Instead, just recreate the install task with a different name. I called it installArchives. Add the following code to your build.gradle:
task installArchives(type: Upload) {
description "Installs the artifacts to the local Maven repository."
repositories.mavenInstaller {
configuration = configurations.default
pom.groupId = 'my.group'
pom.artifactId = 'my-artifact'
pom.version = '1.0.0'
}
}
You can now run gradle installArchives to install your aar locally.
UPDATE 2014-11-26
The answer below made sense at the time of writing, when Android Build Tools were at version 0.5.5. It is most likely outdated now and probably does not work anymore.
I have personally switched my projects to use android-maven-plugin as described in the answer above, the plugin works fine with the recent versions of Android Build Tools too.
THE ORIGINAL ANSWER FROM FEBRUARY 2014
Publishing as AAR
If you don't mind using an older version of com.android.tools.build:gradle (i.e. 0.5.4), you can use the approach described in this blogpost. Not that according to the discussion in adt-dev mailing-list, this does not work in 0.5.5.
Add the following lines to your build.gradle:
apply plugin: 'maven-publish'
// load bundleRelease task
// this will not load the task in 0.5.5
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact bundleRelease
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
Publishing as JAR
If your Android Library does not have custom resources and can be published as JAR, then you can use the following build.gradle that works even with 0.5.5.
// build JAR file
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/classes/release/"
}
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact androidReleaseJar
}
}
}
To publish to your local maven repo, call this command:
gradle publishToMavenLocal
I just solved the issue by defining an upload archive as described here:
Gradle documentation 52.6.2. Deploying to a Maven repository
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
calling
gradle uploadArchives
deploys the artefact to the (in my case local) Maven repo.
I havn't found a simple and more flexible way to specify the local repo's url with e.g. mavenLocal() yet but the above suits my needs.