I've got an Android project split into a pure Java library and the Android application. I'm using Gradle Retrolambda so I can write Java 8 code.
Android Studio 1.3 correctly recognises the android.compileOptions.sourceCompatibility in the Android module that I've set to JavaVersion.VERSION_1_8.
Now I'd like Android Studio to realise the Java module is also Java 8. I've tried (in the root of the Gradle script, after apply plugin 'java':
sourceCompatibility = 1.8 But doesn't work. Gradle correctly compiles, but Android Studio shows a warning ("Assignment not used") and assumes Java 6.
sourceCompatibility 1.8 doesn't compile.
How can I get Android Studio to recognise this without resorting to the "Set source version" quick fix? Or is it unimplemented for now?
EDIT
To clarify, the whole project does compile with ./gradlew assembleDebug. The problem is with Android Studio source highlighting.
My Java module build.gradle is as follows:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
}
}
repositories {
jcenter()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
sourceCompatibility = JavaVersion.VERSION_1_8
dependencies {
compile 'io.reactivex:rxjava:1.0.12'
compile 'io.reactivex:rxjava-string:1.0.0'
compile 'joda-time:joda-time:2.8.1'
testCompile 'junit:junit:4.12'
}
retrolambda {
jdk System.getenv("JAVA_HOME")
defaultMethods true
incremental false
}
And here's what Android Studio gives me:
in your java module build.gradle write code like this:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "me.tatarka:gradle-retrolambda:3.2.0"
}
}
apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'
repositories {
mavenCentral()
}
dependencies {
}
retrolambda {
jdk System.getenv("JAVA8_HOME")
defaultMethods true
incremental false
}
It would appear (thanks #Anand Singh) that Android Studio doesn't handle this yet, so you need to apply the quick fix.
Related
Trying out to use ObjectBox as java desktop database. However after following the documentation on the web site https://docs.objectbox.io/java-desktop-apps its not working. No MyObjectBox found error.
I am using eclipse ide Version: 2020-09 (4.17.0), Gradle: gradle-6.7.1
ObjectBox seems not creating the model automatically after build (no model folder generated). I have created the class using the Entity annotation, build the project eclipse, nothing happens. Anyone any ideas?
Works in android but not desktop. As i am not familiar with gradle project in eclipse. the following is the build file
buildscript {
ext.objectboxVersion = '2.8.1'
repositories {
jcenter()
}
dependencies {
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
}
}
apply plugin: 'java-library'
apply plugin: 'io.objectbox'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
dependencies {
implementation "io.objectbox:objectbox-linux:$objectboxVersion"
implementation "io.objectbox:objectbox-macos:$objectboxVersion"
implementation "io.objectbox:objectbox-windows:$objectboxVersion"
}
apply plugin: 'io.objectbox'
dependencies {
implementation "io.objectbox:objectbox-java:$objectboxVersion"
annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
}
apply plugin: 'io.objectbox'
Doing apply plugin: 'io.objectbox' three times does not look good. Once is enough. Please check the ObjectBox Java examples for a working setup. In your case have a closer look at the java-main example for standalone Java applications.
This is the basic structure with ... where I left out the details (check the full build.gradle file from the example):
buildscript {
...
}
apply plugin: 'java'
apply plugin: 'application'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
mainClassName = "io.objectbox.example.Main"
dependencies {
...
}
// Apply plugin after dependencies block so they are not overwritten.
apply plugin: 'io.objectbox'
Maybe checkout the example and start from there?
I have a gradle spring java project setup, after weeks of it working, Idea suddenly thinks it is an android project, keeps asking me for Android SDK, after deleting .gradle and out/ folders and setting JDK in settings, it compiles and starts, but doesn't copy application.properties file that is required to run the app. Tried restarting, deleting .gradle, .idea, and any other output folder that I could find, but it seems like the only solution that temporarily helps is to clone the repository to a new folder. My suspicion is that I have something in my gradle file that tricks idea to think it's android, but couldn't find anything.
My build.gradle
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
ext {
springVersion = "4.3.12.RELEASE"
springBootVersion = '2.1.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.ebean:ebean-gradle-plugin:11.34.1")
}
}
apply plugin: SpringBootPlugin
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.ebean'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-websocket:${springBootVersion}")
implementation("org.mindrot:jbcrypt:0.3m")
implementation('io.jsonwebtoken:jjwt-api:0.10.5')
runtime "io.jsonwebtoken:jjwt-impl:0.10.5", "io.jsonwebtoken:jjwt-jackson:0.10.5"
implementation("org.springframework:spring-jdbc:${springVersion}")
implementation("org.apache.logging.log4j:log4j-core:2.11.1")
implementation("org.postgresql:postgresql:42.2.5")
implementation("org.apache.tomcat:tomcat-jdbc:9.0.8")
implementation("io.ebean:ebean:11.36.1")
implementation("io.ebean:ebean-agent:11.11.1")
implementation("io.ebean:ebean-spring-txn:11.10.4")
testImplementation("junit:junit:'4.+")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
Clean IDE project specific files and regenerate them with
./gradlew cleanIdea idea
Then try to import project again.
I am making an IntelliJ project of Serenity BDD that will use Java 10. The exact project I am using is built from the maven command, (Using option 3 for just Selenium-Junit):
mvn archetype:generate -Dfilter=serenity
So far I have corrected for the JAXB exception when building/running in Java 10 with the following dependencies in my build.gradle
compile 'javax.xml.bind:jaxb-api:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.0'
compile 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
compile 'javax.activation:activation:1.1.1'
I have also installed the Java 10 Jdk (jdk-10.0.1_windows-x64_bin), and pointed my project to that Jdk. I've also found instruction to update my Gradle to version 4.8, and have done so as well
I'm trying to handle any other compatibility issues, and I'm trying to understand the gradle dependencies process better. With my entire build.gradle posted below, What else do I need to change to ensure that my build.gradle is helping to maintain Java 10?
repositories {
jcenter()
mavenLocal()
}
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:1.8.3")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile 'net.serenity-bdd:serenity-core:1.8.3'
compile 'net.serenity-bdd:serenity-junit:1.8.3'
compile 'javax.xml.bind:jaxb-api:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.0'
compile 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
compile 'javax.activation:activation:1.1.1'
compile 'net.serenity-bdd:serenity-rest-assured:1.2.5-rc.11'
testCompile 'org.slf4j:slf4j-simple:1.7.7'
testCompile('junit:junit:4.12')
}
gradle.startParameter.continueOnFailure = true
I have a java project that write in kotlin ,i use intelliJ IDEA to develop this project. I have trouble on the dependencies setting (multiple project). I already read lot of examples , but I can't find the workaround , here is my dependencies setting code,
it can be build in java class correctly , but the kotlin class will get lot of error 'Unresolved reference' . Is that any wrong about my setting or gradle is not suitable with kotlin .
PS : when i only build core project , build process will successful , but build at test project will get the reference unresolved error
allprojects {
apply plugin: 'java'
apply plugin: 'kotlin'
group 'testProject'
version '1.0'
}
subprojects{
apply plugin: 'java'
apply plugin: 'kotlin'
def defaultEncoding = 'UTF-8'
compileJava.options.encoding = defaultEncoding
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
// Kotlin
compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}
project(':test') {
dependencies {
compile project(':core')
compile project(':testTwo')
}
project(':testTwo'){
dependencies{
compile project(':core')
}
setting.gradle
include 'test','testTwo','core'
The kotlin-gradle-plugin is not a dependency of your subprojects, it is a dependency of the buildscript itself.
Follow the instructions on Plugin and Versions
my gradle project was build succeed, but when add spoon ,then i got this error (Could not create plugin of type 'AppPlugin')
my gradle version 1.9
build.gradle :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.9.+'
}
}
apply plugin: 'android'
apply plugin: 'spoon'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.5'
}
The minimum supported version Android plugin is 0.8. However there is no good documentation against what Spoon plugin version should be used with what version of Android plugin at the moment.
I recommend using the latest versions of both plugins, which will also require newer Gradle version.
P.S.
There was a github issue raised by you: https://github.com/stanfy/spoon-gradle-plugin/issues/14. Right? :)