I have a multiproject gradle project
project_android
project_lib
app
project-lib is in its own git repository which I added to to project_android using git subtree.
I'm stuck. In order to build project_lib by itself, I need to specify a version for this plugin. If I don't have the version
plugins {
id 'org.jetbrains.kotlin.jvm'
}
I get this error when building
* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
```
So I add a version and then it works
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.7.10"
}
But now I can't build project_android, here is the error
Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
> Plugin request for plugin already on the classpath must not include a version
I haven't added this plugin to app so I don't know where it comes from. This is the plugins in project_android/app/build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
// Kotlin Annotation Processing Tool
id 'kotlin-kapt'
// Google Services plugin
id 'com.google.gms.google-services'
// Navigation
id 'androidx.navigation.safeargs.kotlin'
// Performance Monitoring plugin
id 'com.google.firebase.firebase-perf'
}
One project requires me to add a version. Another requires me not to add a version. What do I do to keep both happy?
Usually when I run into this it's because there is another implementation of that plug-in in one of the other gradle files. Look in your build.gradle project file and/or your gradle settings file to see if another version of 'org.jetbrains.kotlin.jvm' is listed. You may have to play around with deleting it from one of those other files and resyncing the gradle until it works.
I resolved this by using the gradle legacy plugin dsl. In project_lib\build.gradle instead of:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.17.10'
}
I instead do this
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
apply plugin: "org.jetbrains.kotlin.jvm"
I am integrating OAuth login for Google+ on my android application, following the tutorial.
According to the tutorial, I should add the Google Service plugin by adding
classpath 'com.google.gms:google-services:1.0' dependency to top-level build.gradle in my android project.
However, when I sync the gradle with the changes, I see the error as follows:
Error:Could not find com.google.gms:google-services:1.0.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/google/gms/google-services/1.0/google-services-1.0.jar
https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.pom
https://jcenter.bintray.com/com/google/gms/google-services/1.0/google-services-1.0.jar
In my 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:1.2.3'
classpath 'com.google.gms:google-services:1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
It seems that the android studio is not able to find google-services plugin from repositories.
Does anybody have the same issue? Or, am I missing something?
I ran into the same issue today. In the samples they use this line instead:
classpath 'com.google.gms:google-services:1.3.0-beta1'
This works.
For me I had to switch the repository to jcenter(). I was using mavenCentral and getting this error. As soon as I switched to jcenter() it pulled the dependency down.
To do this, open your build.gradle and replace each instance of mavenCentral() with jcenter()
Google updated their guide. Where it was classpath 'com.google.gms:google-services:1.0' now reads classpath 'com.google.gms:google-services:1.3.0-beta1' like joluet suggested.
Google now released the plugin v1.3.0
I was able to solve it using this:
classpath 'com.google.gms:google-services:1.3.0'
I resolved this issue by doing the following things:
In build.gradle (at project level):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
mavenCentral()
}
}
In build.gradle (at module level):
On top added:
apply plugin: 'com.google.gms.google-services'
and in dependecies added:
compile 'com.google.android.gms:play-services-analytics:8.3.0'
Apart from this make sure you have updated the Google Play services and Google repository in the SDK.
As of 25th Nov,2015, google released a newer version.
Try adding:
classpath 'com.google.gms:google-services:2.0.0-alpha1'
And don't forget to add jcenter() repository under buildscript.
Thanks.
I think you forgotten gradle's project level,
From developers page:
Add the dependency to your project-level build.gradle
classpath 'com.google.gms:google-services:1.5.0-beta2'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Google has updated GCM go check it and for that you have to update your Android Studio too.
I would advise you against doing what you are doing. I did it too (by following Set up a GCM Client App on Android blindly) but ended up with exceeding 65K method limit.
So, you should remove the following lines from your gradle:
apply plugin: 'com.google.gms.google-services'
classpath 'com.google.gms:google-services:1.0'
Now import APIs of Google Plus with simple gradle import:
compile 'com.google.android.gms:play-services-plus:8.1.0'
Adding jcenter repository to project level build.gradle helped in my case:
buildscript {
repositories {
jcenter();
mavenCentral()
}
I was trying to setup firebase for my android app when I faced this problem. Following screenshot should clarify things -
Couple of things I would like to point out -
1. Once you
apply plugin: 'com.google.gms.google-services'
This line should be at the bottom of the app level gradle file. Not sure why but putting at the top did not workout for me.
If you use Android Studio, try to add google service with the IDE.
Right click on folder module.
On left list at Developer Services choose desired service.
Wait for syncing and the IDE will automatically add google dependecies.
add classpath on buildscript
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:1.3.0-beta1'
}
}
You maybe miss this step
Copy the google-services.json file you just downloaded into the app/ or mobile/ directory of your Android Studio project. Open the Android Studio Terminal pane:
$ move path-to-download/google-services.json app/
Have fun.
You need to check the current version as in the link below says, by now:
classpath 'com.google.gms:google-services:1.3.0-beta4'
Check this answer:
Update gradle version
We have to look for the last version in my case was:
dependencies {
classpath 'com.google.gms:google-services:1.4.0-beta3'
}
Here you can find a list of the versions.
I got a similar problem while following the instructions for implementing a GCM client in Android Studio, however, the message I got was :
Error: Could not find com.google.gms:google-services:1.3.0-beta1...
Although I never figured out what was wrong, I simply copied my sources, resources, manifest, and keystore into a new Android Studio project. I then edited the auto-generated gradle build files for the new project by manually re-adding my dependencies.
I made sure not to copy over my build files from the old project verbatim (since the source of the error likely lay in them somewhere).
It is not a satisfying solution, but it worked for me and it took little time.
For me adding this under dependencies worked
compile 'com.google.gms:google-services:3.0.0'
Inside the .idea folder exists a workspace.xml file that defines the project's structure. I suggest you to close Android Studio, then delete .idea folder and then import the project again. The .idea would be generated by the IDE again. For me this solution works.
You should just add classpath 'com.google.gms:google-services:1.3.0-beta1' to dependencies of your (Top level build file) the build.gradle that has the (Project:<name of your project). Hope this helps!
I recently updated to Android Studio 2.3 and somehow apply plugin doesn't work.
After that, I tried various ways and then what work is when I commented out app's build.gradle:
apply plugin: 'com.google.gms.google-services'
and then I add this to top-level build.gradle (below classpath 'com.android.tools.build:gradle:2.2.3'):
classpath 'com.google.gms:google-services:3.0.0'
and then it works.
I have a Eclipse workspace with a declared workset configured to have several projects. Some are to generate JAR files and others are web applications that use those JAR files. In my architecture I have a JAR that will consist of domain core services and another one that depends on the first one that will consist of higher level services. Finally I will have some web applications that use those both JARs.
The first JAR project is build with Gradle, based on the following script
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
mavenLocal()
mavenCentral();
}
jar {
baseName = 'br.ufpr.unidades.dominio'
version = '0.1.0'
}
dependencies {
compile 'org.hibernate:hibernate-core:4.3.7.Final'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
As anyone can see, it´s a very simple build.gradle file and the build works fine with it. The expected JAR file is generated in the expected destination folder.
Now, here comes the build script for the second JAR:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
mavenLocal()
mavenCentral()
}
jar {
baseName = 'br.ufpr.unidades.dominio.hibernate'
version = '0.1.0'
}
dependencies {
runtime fileTree(dir: '../dominio/build/libs', include: '*.jar')
compile 'org.hibernate:hibernate-core:4.3.7.Final'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
The second file is very similar to the first one, except it has a dependency on generated JAR:
runtime fileTree(dir: '../dominio/build/libs', include: '*.jar')
Eclipse doesn´t show any problems, but when I try to build the second JAR project I get many Class not found error messages, like the one below:
[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] build
[sts] -----------------------------------------------------
:compileJava
D:\Users\alex\Documents\Eclipse\workspace\unidades\dominio.hibernate\src\main\java\dominio\hibernate\HibernateCargoRepository.java:7: error: package unidades.dominio does not exist
import unidades.dominio.Cargo;
The message is clear: I´m importing a package that is not being found during the build, so the classes such a package has cannot be referenced in my code. Such a package is declared in the first and perfectly generated JAR file. It also is visible under Referenced Libraries item in the Eclipse project, so Gradle was able to find it to reference it in design time, but not to build the second JAR.
After all that, I suspect it´s a dependency management problem, but I can´t see which it is and how to fix it.
Thanks in advance!
Are You using classes from the jar under dominio/build/libs in the second project? If so, this should be a compile dependency. I'd also recommend setting a multimodule gradle project. Here are the docs.
Is there a gradle plugin to package Java Webstart (JWS) applications, similar to what Maven webstart plugin does? I need to automate at least the following tasks:
jnlp descriptor generation based on an existing template, automatic adding project dependencies;
jar signing based on the files described on jnlp file or project dependencies;
As of Aug 2016, the answer is "no".
There is a plugin under development per #Jake's answer. But there is no turn key solution. You'll have to do the work yourself to create a webstart app in Gradle... either with your own custom solution or by contributing to the plugin mentioned until it works for you.
Here's the plugin direct link: https://github.com/tschulte/gradle-jnlp-plugin
Found the following link outside of Stack Overflow and looks like it does some of what you are looking for but not all. Hopefully this gets you closer to what you need...
This is an old post, but answering anyway.
I could configure gradle-jnlp-plugin.
Steps:
-Create an empty folder.
-Create src folder with Java code. I used the sample AccessibleScrollDemo.
-Copy keystore.ks from examples or create your own using genkey task in plug-in.
-Create build.gradle with following configuration.
The plug-in has examples of various options for jnlp task.
-Run plug-in task using gradle (v2.4 or more).
gradle createWebstartDir
-This will create the jnlp file under build directory, and also jars in build/lib.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.gliderpilot.gradle.jnlp:gradle-jnlp-plugin:+'
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'groovy'
apply plugin: 'de.gliderpilot.jnlp'
group = 'misc'
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenCentral()
}
mainClassName = 'misc.AccessibleScrollDemo'
sourceSets {
main.java.srcDir "src"
}
dependencies {
runtime('log4j:log4j:1.2.17') {
exclude group: 'ant', module: 'ant-nodeps'
exclude group: 'ant', module: 'ant-junit'
exclude group: 'ant-contrib', module: 'ant-contrib'
}
runtime 'org.slf4j:slf4j-log4j12:1.7.21'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
jnlp {
useVersions = false
usePack200 = false
withXml {
information {
title project.name
vendor project.group ?: project.name
}
security {
'all-permissions'()
}
}
signJarParams = [keystore: 'keystore.ks', alias: 'myalias', storepass: 'mystorepass']
}
compileGroovy.enabled = false
afterEvaluate {
// prevent ClassCastException
project.version = project.version.toString()
}
}
I think the Gradle JNLP Plugin currently registered in the Gradle Plugins directory may be the project for which you're looking.
Tobias Schulte's Gradle JNLP Plugin ( tschulte/gradle-jnlp-plugin on GitHub ) was striving for this about a year ago, but the new plugin is both registered in the Gradle Plugin site and looks to be under much more active development.
Following the explanation in "Building and Testing with Gradle" I have a multiproject gradle setup like this:
rootFolder
build.gradle
settings.gradle
EMS
build.gradle
cloud-sdk
build.gradle
The cloud-sdk project depends on several jars, partially resolved via maven partially via locale jars:
// file: cloud-sdk/build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group:'org.apache.tomcat', name:'tomcat-catalina', version:'7.0.47'
compile group:'org.mongodb', name:'mongo-java-driver', version:'2.11.3'
compile group:'com.google.code.gson', name:'gson', version:'2.2.4'
compile group:'com.thoughtworks.xstream', name:'xstream', version:'1.4.6'
compile fileTree(dir:'lib/', include:'JavaPNS_2.2.jar')
compile fileTree(dir:'lib/', include:'gcm-server.jar')
}
The EMS-project depends on the cloud-sdk which I think should be defined like this:
// file: EMS/build.gradle
apply plugin: 'java'
dependencies {
compile project(':cloud-sdk')
}
Furthermore, my root build.gradle and settings.gradle files look like this:
settings.gradle
include 'cloud-sdk', 'EMS'
build.gradle
apply plugin: 'java'
dependencies {
compile project(':EMS')
}
In this case I am not sure whether I also need the dependency compile project (':cloud-sdk'). I tried both version but since I get the same error message in both cases I assume it doesn't matter.
When I try to run the script from the rootFolder via gradle build I get the following error messages:
Could not resolve all dependencies for configuration ':EMS:compile'.
> Could not find org.apache.tomcat:tomcat-catalina:7.0.47.
Required by:
rootFolder:EMS:unspecified > rootFolder:cloud-sdk:unspecified
> Could not find org.mongodb:mongo-java-driver:2.11.3.
Required by:
rootFolder:EMS > rootFolder:cloud-sdk:unspecified
> Could not find com.google.code.gson:gson:2.2.4.
Required by:
rootFolder:EMS > rootFolder:cloud-sdk:unspecified
> Could not find com.thoughtworks.xstream:xstream:1.4.6.
Required by:
rootFolder:EMS:unspecified > rootFolder:cloud-sdk:unspecified
But when I just build the cloud-sdk project via gradle cloud-sdk:build gradle downloads the required jars and builds the project without a problem.
But even if I try gradle build after that, although gradle notices that the cloud-sdk project is already up-to-date, it complains about the missing dependencies.
Why is that? It downloaded them already so they should be available somewhere and even if not the cloud-sdk knows what it needs and how to fetch it. What am I missing? Do I need to specify the dependencies in some other way?
Ok, it turns out gradle could not fetch the dependencies in the EMS project since I did not specify any repositories to fetch them from. I assumed that would not be necessary since the only dependencies I needed it to fetch were declared in the cloud-sdk project and that did have a repository given.
This is basically the solution to my problem, but if anybody can explain to me why it is necessary to specify the repository again or explain why it is a bug in gradle that should be fixed, I'll accept that answer as it would answer the "why" and not just the "how do I get it to work".