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"
Related
I am trying to run spring-boot project. I have some problem with gradle.
gradle build works fine, but I cannot run gradlew
Cannot run command:
./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
Here is error:
Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9
My gradle version 6.0
My gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.postgresql:postgresql')
testCompile("org.springframework.boot:spring-boot-starter-test")
}
gradle build works fine, there is no error.
The whole point of the Gradle wrapper is to have a fixed version of Gradle used in a project. This ensures that you don't by accident use an incompatible version than what the project supports. Another benefit is that it automatically downloads the correct version if you don't have it already.
When you type gradle (without the 'w'), you are invoking a manually downloaded distribution that you put on your path. This skips the wrapper part completely. In your case, you have apparently downloaded version 6 and updated the project to work with that version.
However, you have not updated the wrapper scripts, which is what you should have done instead. If you look in gradle/wrapper/gradle-wrapper.properties, you should see that it is set to 4.9, which is no longer compatible with your project.
To update it, you need to run the following command twice:
gradlew wrapper --gradle-version 6.1.1 --distribution-type all (assuming you want version 6.1.1, which is the latest at the time of this writing.)
The first time you run it, it will basically just change the version in gradle-wrapper.properties (e.g to 6.1.1). If this fails because the wrapper is too old compared to the project, just change the file manually with a text editor.
The second time you run it, Gradle will start up using that new version (e.g. 6.1.1) and, if needed, update the wrapper scripts themselves.
Also, if you like to start your Spring Boot application during development, just run gradlew bootRun. No need to build the jar and invoke java manually.
And also, instead of compile, use implementation in your dependencies. The former is deprecated (including testCompile).
I have a java project that is using dagger-2 and grpc, when I try to build it using ./gradlew build I get the following error:
> java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
is MoreTypes supposed to be provided inside of dagger-2 dependencies or I should provide that dependency on the class path?
this is the relevant parts of gradle.build file content:
plugins {
id "net.ltgt.apt" version "0.10"
id "com.google.protobuf" version "0.8.1"
id "java"
}
dependencies {
compile 'io.grpc:grpc-all:1.5.0'
compile 'com.google.dagger:dagger:2.14'
apt 'com.google.dagger:dagger-compiler:2.14'
testApt 'com.google.dagger:dagger-compiler:2.14'
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
This is a problem in Dagger 2.14 fixed in 2.14.1. See issue 994, "Dagger 2.14 breaks build":
I have not isolated the issue to a small sample project at this point, but a possible cause I see is below, maybe that gives a pointer. I don't have any explicit dependency on Google Auto libs in that part of the build.
java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
Confirmed fixed in 2.14.1, which contains this commit.
When trying to build my java project using Gradle I get the following issue:
plugin with id 'sonar' not found
at the following line in my build.gradle:
apply plugin: 'sonar'
This was previously working with Gradle version 1.7 and Java 7, however I have now updated to these newer versions:
gradle : 3.4.1
Java: 1.8
What could be causing this and how could I solve it?
The sonar plugin was renamed to 'org.sonarqube'.
To use this plugin you need to add a dependency:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
}
}
And then you can apply the plugin:
apply plugin: "org.sonarqube"
Also see the plugin page.
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.
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.