unable to find Kodein-db-0.8.1-beta-samplesources.jar in KMP application - build.gradle

I want to add Kodein to my application but I can't add it, it seems.
This is the error I get:
Could not find kodein-db-0.8.1-beta-samplessources.jar (org.kodein.db:kodein-db:0.8.1-beta).
Searched in the following locations:
https://repo.maven.apache.org/maven2/org/kodein/db/kodein-db/0.8.1-beta/kodein-db-0.8.1-beta-samplessources.jar
I have this in
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.kodein.db:kodein-db:0.8.1-beta")
implementation("org.kodein.db:kodein-db-serializer-kotlinx:0.8.1-beta")
in my project level build.gradle.kts I have this:
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
val kotlinVersion = "1.4.32"
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.android.tools.build:gradle:4.2.1")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
}
}
extra.set("kodeinVersion", "7.2.0")
allprojects {
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://dl.bintray.com/kodein-framework/kodein-dev")
}
}
I removed the last line in the repositories and it still failed with the same error.

Related

'kotlinx.serialization.json.Json'. Check your module classpath for missing or conflicting dependencies

I am trying to use kotlinx.serialization in my KMM application to parse a json Http response from a website. I have tried many of the solutions that I have found on the web but non have solved my problem. I had to update to Android Studio/Kotlin Version 1.5.20 to eliminate an error in the Kotlin-datetime module. Know facing new compiler errors. Can anyone help?
Kotlin class:
import com.pagetyler.dailynasa.shared.entity.Defaults
import io.ktor.client.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.client.request.*
class NasaPicsApi {
private val httpClient = HttpClient {
install(JsonFeature) {
val json = kotlinx.serialization.json.Json { ignoreUnknownKeys = true }
serializer = KotlinxSerializer(json)
}
}
suspend fun getPicture(currDate:String): List<NasaPicture> {
val ep = "$PICTURES_ENDPOINT$EXTENSION?api_key=$DEFAULT_APIKEY;date=$currDate "
return httpClient.get(ep)
}
companion object {
private val PICTURES_ENDPOINT = Defaults().PICTURES_ENDPOINT
private val EXTENSION = Defaults().EXTENSION
private val DEFAULT_APIKEY = Defaults().DEFAULT_APIKEY
}
}
Common/Shared build.gradle.kts:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val kotlinVersion = "${rootProject.extra["kotlin_version"]}"
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization") version "1.5.20"
id("com.android.library")
id("com.squareup.sqldelight")
}
group = "com.pagetyler"
version = "1.0-SNAPSHOT"
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/") // soon will be just jcenter()
}
kotlin {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
useIR = true
}
}
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "shared"
}
}
}
jvm().compilations.all {
kotlinOptions {
useIR = true
}
}
android()
val ktorVersion = "1.4.0"
val serializationVersion = "1.0.0-RC-$kotlinVersion"
val sqlDelightVersion: String by project
val coroutinesVersion = "1.3.9-native-mt"
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation(kotlin("stdlib-common"))
implementation("com.squareup.sqldelight:runtime:$sqlDelightVersion")
//implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
//implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("io.ktor:ktor-client-android:$ktorVersion")
implementation("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation("com.squareup.sqldelight:native-driver:$sqlDelightVersion")
}
}
val iosTest by getting
}
}
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(24)
targetSdkVersion(30)
versionCode = 2
versionName = "2.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
sqldelight {
database("PicturesDB") {
packageName = "com.pagetyler.shared.cache"
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets.getByName<KotlinNativeTarget>
("ios").binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
This is the Global build.gradle.kts
buildscript {
val kotlin_version by extra("1.5.20")
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/") // soon will be just jcenter()
}
val sqlDelightVersion= "1.5.0"
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlin_version")
classpath("com.squareup.sqldelight:gradle-plugin:$sqlDelightVersion")
file("libs\\YouTubeAndroidPlayerApi.jarlibs\\YouTubeAndroidPlayerApi.jar")
}
}
apply (plugin = "com.squareup.sqldelight")
apply (plugin = "kotlin")
group = "com.pagetyler"
version = "1.0-SNAPSHOT"
allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven(url = "https://kotlin.bintray.com/kotlinx/") // soon will be just jcenter()
}
}
This issue appears to be unique to Android Studio 4.2.2 Beta 5. I did not have it before I migrated to it. The problem went away when I migrated to the next release of Artic Fox 2020.3.1.
Avoid using Android Studio 4.2.2 Build #AI-202.7660.26.42.7486908, built on June 23, 2021 if you can.

Gradle Kotlin Build Script unable to get SpringBoot Lib

i tried few way on my build script but still unsuccessful to get the springboot lib in to my jar, may i know what's wrong with my script as below ?
Parent Gradle Kotlin DSL
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
extra["kotlin.version"] = "1.3.31"
plugins {
java
idea
id("org.springframework.boot") version "2.1.4.RELEASE" apply false
kotlin("jvm") version "1.3.31" apply false
kotlin("plugin.spring") version "1.3.31" apply false
}
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
apply(plugin = "io.spring.dependency-management")
the<DependencyManagementExtension>().apply {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
group = "com.company.market"
version = System.getenv("VERSION") ?: "0.2-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
repositories {
maven {
credentials {
username = "anonymous"
password = "anonymous"
}
url = uri("http://repo1.maven.apache.org/maven2/")
}
}
dependencies {
implementation(kotlin("reflect"))
implementation(kotlin("stdlib-jdk8"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.getByName<KotlinCompile>("compileKotlin") {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
tasks.getByName<KotlinCompile>("compileTestKotlin") {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
}
Child (API) Gradle Kotlin DSL
Here are the child module that will used for deployment
plugins {
`java`
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE")
implementation("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.4.RELEASE")
implementation("org.springframework.boot:spring-boot-devtools")
implementation("org.apache.commons:commons-dbcp2")
implementation("org.mariadb.jdbc:mariadb-java-client")
implementation("org.springframework.boot:spring-boot-loader:2.1.4.RELEASE")
implementation(project(":app-expr"))
implementation(project(":app-data"))
}
i can success build the api module but jar size is small and realize the lib were not build inside the jar.
i added the springboot lib in my sub proj and solved
plugins {
`java`
id("org.springframework.boot")
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE")
implementation("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.4.RELEASE")
implementation("org.springframework.boot:spring-boot-devtools")
implementation("org.apache.commons:commons-dbcp2")
implementation("org.mariadb.jdbc:mariadb-java-client")
implementation("org.springframework.boot:spring-boot-loader:2.1.4.RELEASE")
implementation(project(":expr"))
implementation(project(":data"))
}

Jhipster gradle build 6.0.0 jdk-11 How to fix a failing build?

I created a project with JHipster 6.0.0-beta.0 and java version openjdk-11.0.2_windows-x64
I get the following error.
Task :bootRun FAILED
Error: Could not find or load main class com.jhipster.demo.desc.DescApp
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/InitializingBean
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\OpenJDK11\bin\java.exe'' finished with non-zero exit value 1
Here is my build.gradle file
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "io.spring.gradle:propdeps-plugin:0.0.10.RELEASE"
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven"
id "war"
id "idea"
id "jacoco"
id "com.google.cloud.tools.jib" version "0.9.11"
id "com.gorylenko.gradle-git-properties" version "2.0.0"
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.21"
id "net.ltgt.apt" version "0.21"
id "org.liquibase.gradle" version "2.0.1"
id "org.sonarqube" version "2.7"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
sourceCompatibility=1.8
targetCompatibility=1.8
assert System.properties["java.specification.version"] == "1.8" || "11" || "12"
apply plugin: "org.springframework.boot"
apply plugin: "propdeps"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/source/apt/main"]
}
}
}
}
defaultTasks "bootRun"
group = "com.jhipster.demo.desc"
version = "0.0.1-SNAPSHOT"
description = ""
bootWar {
mainClassName = "com.jhipster.demo.desc.DescApp"
includes = ["WEB-INF/**", "META-INF/**"]
}
war {
enabled = true
extension = "war.original"
includes = ["WEB-INF/**", "META-INF/**"]
}
springBoot {
mainClassName = "com.jhipster.demo.desc.DescApp"
}
if (OperatingSystem.current().isWindows()) {
// https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle
task classpathJar(type: Jar) {
dependsOn configurations.runtime
appendix = "classpath"
doFirst {
manifest {
attributes "Class-Path": configurations.runtime.files.collect {
it.toURI().toURL().toString().replaceFirst(/file:\/+/, "/").replaceAll(" ", "%20")
}.join(" ")
}
}
}
bootRun {
dependsOn classpathJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", classpathJar.archivePath)
}
}
}
test {
exclude "**/*IT*", "**/*IntTest*", "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
exclude "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
description = "Execute cucumber BDD tests."
group = "verification"
include "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn cucumberTest
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
task cucumberTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn cucumberTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/desc"
username "root"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName "desc"
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/desc"
username "root"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.jhipster.demo.desc.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName "desc"
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}" )
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "com.hazelcast:hazelcast"
implementation "com.hazelcast:hazelcast-hibernate53"
implementation "com.hazelcast:hazelcast-spring"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate:hibernate-envers"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-data-elasticsearch"
// Spring Data Jest dependencies for Elasticsearch
implementation ("com.github.vanroy:spring-boot-starter-data-jest") {
exclude module: "commons-logging"
}
// log4j2-mock needed to create embedded elasticsearch instance with SLF4J
runtimeOnly "de.dentrassi.elasticsearch:log4j2-mock:0.0.1"
// end of Spring Data Jest dependencies
implementation "org.springframework.cloud:spring-cloud-stream"
implementation "org.springframework.cloud:spring-cloud-stream-binder-kafka"
implementation "org.springframework.kafka:spring-kafka"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "io.jsonwebtoken:jjwt-api"
runtimeOnly "io.jsonwebtoken:jjwt-impl"
runtimeOnly "io.jsonwebtoken:jjwt-jackson"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "com.jayway.jsonpath:json-path"
testImplementation "io.cucumber:cucumber-junit"
testImplementation "io.cucumber:cucumber-spring"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation "junit:junit"
testImplementation "org.mockito:mockito-core"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "com.h2database:h2"
testImplementation "org.springframework.cloud:spring-cloud-stream-test-support"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "5.3.1"
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
I would expect this to compile successfully.
Updated Gradle File (4/12/19)
import org.gradle.internal.os.OperatingSystem
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
classpath "io.spring.gradle:propdeps-plugin:0.0.10.RELEASE"
**classpath "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
classpath "javax.xml.bind:jaxb-api:${jaxb_api_version}"**
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven"
id "war"
id "idea"
id "jacoco"
id "com.google.cloud.tools.jib" version "0.9.11"
id "com.gorylenko.gradle-git-properties" version "2.0.0"
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.21"
id "net.ltgt.apt" version "0.21"
id "org.liquibase.gradle" version "2.0.1"
id "org.sonarqube" version "2.7"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
**sourceCompatibility=1.11
targetCompatibility=1.11**
assert System.properties["java.specification.version"] == "1.8" || "11" || "12"
apply plugin: "org.springframework.boot"
apply plugin: "propdeps"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/source/apt/main"]
}
}
}
}
defaultTasks "bootRun"
group = "com.jhipster.demo.descriptions"
version = "0.0.1-SNAPSHOT"
description = ""
bootWar {
mainClassName = "com.jhipster.demo.descriptions.DescriptionsApp"
includes = ["WEB-INF/**", "META-INF/**"]
}
war {
enabled = true
extension = "war.original"
includes = ["WEB-INF/**", "META-INF/**"]
}
springBoot {
mainClassName = "com.jhipster.demo.descriptions.DescriptionsApp"
}
if (OperatingSystem.current().isWindows()) {
// https://stackoverflow.com/questions/40037487/the-filename-or-extension-is-too-long-error-using-gradle
task classpathJar(type: Jar) {
dependsOn configurations.runtime
appendix = "classpath"
doFirst {
manifest {
attributes "Class-Path": configurations.runtime.files.collect {
it.toURI().toURL().toString().replaceFirst(/file:\/+/, "/").replaceAll(" ", "%20")
}.join(" ")
}
}
}
bootRun {
dependsOn classpathJar
doFirst {
classpath = files("$buildDir/classes/java/main", "$buildDir/resources/main", classpathJar.archivePath)
}
}
}
test {
exclude "**/*IT*", "**/*IntTest*", "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
exclude "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task cucumberTest(type: Test) {
description = "Execute cucumber BDD tests."
group = "verification"
include "**/*CucumberIT*"
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn cucumberTest
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
task cucumberTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn cucumberTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/descriptions"
username "root"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName "descriptions"
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "com.mysql.jdbc.Driver"
url "jdbc:mysql://localhost:3306/descriptions"
username "root"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.jhipster.demo.descriptions.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName "descriptions"
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}" )
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "com.hazelcast:hazelcast"
implementation "com.hazelcast:hazelcast-hibernate53"
implementation "com.hazelcast:hazelcast-spring"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate:hibernate-envers"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-data-elasticsearch"
// Spring Data Jest dependencies for Elasticsearch
implementation ("com.github.vanroy:spring-boot-starter-data-jest") {
exclude module: "commons-logging"
}
// log4j2-mock needed to create embedded elasticsearch instance with SLF4J
runtimeOnly "de.dentrassi.elasticsearch:log4j2-mock:0.0.1"
// end of Spring Data Jest dependencies
implementation "org.springframework.cloud:spring-cloud-stream"
implementation "org.springframework.cloud:spring-cloud-stream-binder-kafka"
implementation "org.springframework.kafka:spring-kafka"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "io.jsonwebtoken:jjwt-api"
runtimeOnly "io.jsonwebtoken:jjwt-impl"
runtimeOnly "io.jsonwebtoken:jjwt-jackson"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
**implementation "javax.xml.bind:jaxb-api:${jaxb_api_version}"
annotationProcessor "javax.xml.bind:jaxb-api:${jaxb_api_version}"
implementation "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"**
annotationProcessor ("org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "com.jayway.jsonpath:json-path"
testImplementation "io.cucumber:cucumber-junit"
testImplementation "io.cucumber:cucumber-spring"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "com.vaadin.external.google", module: "android-json"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation "junit:junit"
testImplementation "org.mockito:mockito-core"
testImplementation "org.hamcrest:hamcrest-library"
testImplementation "com.h2database:h2"
testImplementation "org.springframework.cloud:spring-cloud-stream-test-support"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "5.3.1"
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
I believe you can fix this by adding JAXB to your build.gradle:
implementation 'org.glassfish.jaxb:jaxb-runtime'
If this works, please open an issue (or create a PR) in the JHipster project on GitHub.

Could not find org.jetbrains.trove4j: trove4j: 20160824

I am trying to build libGDX project for Android via Gradle.
I get following error: Could not find org.jetbrains.trove4j: trove4j: 20160824.
I have tried every combination of:
jCenter(), mavenLocal(), mavenCentral(), google()
In my build.gradle files, root and android's one.
Also tried different orders of it, as suggested by others in other forums.
What sould I do?
Full error:
Could not resolve all files for configuration ':android:debugCompileClasspath'.
> Could not find org.jetbrains.trove4j:trove4j:20160824.
Searched in the following locations:
- file:/media/mruser/Data/AndroidSDK/extras/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- file:/media/mruser/Data/AndroidSDK/extras/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- file:/media/mruser/Data/AndroidSDK/extras/google/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- file:/media/mruser/Data/AndroidSDK/extras/google/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- file:/media/mruser/Data/AndroidSDK/extras/android/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- file:/media/mruser/Data/AndroidSDK/extras/android/m2repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- file:/home/mruser/.m2/repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- file:/home/mruser/.m2/repository/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://dl.google.com/dl/android/maven2/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://oss.sonatype.org/content/repositories/snapshots/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://oss.sonatype.org/content/repositories/snapshots/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- https://oss.sonatype.org/content/repositories/releases/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.pom
- https://oss.sonatype.org/content/repositories/releases/org/jetbrains/trove4j/trove4j/20160824/trove4j-20160824.jar
- file:/home/mruser/GDX/ColorGame/libs/trove4j-20160824.jar
- file:/home/mruser/GDX/ColorGame/libs/trove4j.jar
Required by:
project :android
Root build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.3'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "ColorfulGame"
gdxVersion = '1.9.8'
roboVMVersion = '2.3.3'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
flatDir {
dir rootProject.file( 'libs' )
}
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.1.1'
compile group: 'org.jetbrains.trove4j', name: 'trove4j', version: '20160824'
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
dependencies {
compile project(":core")
compile "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
compile "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile files("libs/SGDX.jar")
}
}
tasks.eclipse.doLast {
delete ".project"
}
Android build.gradle:
android {
buildToolsVersion "28.0.3"
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
packagingOptions {
exclude 'META-INF/robovm/ios/robovm.xml'
}
defaultConfig {
applicationId "sk.ap.cg"
minSdkVersion 9
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'sk.ap.cg/sk.ap.cg.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += [ project.configurations.compile ]
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
Problem was asociated with mavenCentral() and mavenLocal().
allproject and buildfile closures in root buildfile should look like this:
repositories {
jcenter()
google()
}
If someone still looks for solution and mavens are ok - in my case problem was with outdated react-native-document-picker library. I installed last version and problem has gone. So be sure problem is not caused by your libraries.

Searching Latlng inside Polygon is not precise

I am trying to check if map centre is inside a polygon or not. My code for creating mulitple polygons on map is this:
for (int i = 0; i < Constant.arr_zone.size(); i++) {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
ArrayList<LatLng> list = new ArrayList<>();
for (int j = 0; j < Constant.arr_zone.get(i).polygon.length; j++) {
list.add(new LatLng(Constant.arr_zone.get(i).polygon[j].geo_x,
Constant.arr_zone.get(i).polygon[j].geo_y));
builder.include(list.get(j));
}
polygonOptions = new PolygonOptions();
polygonOptions.addAll(list);
polygonOptions.strokeColor(R.color.theme_color);
polygonOptions.strokeWidth(2);
polygonOptions.fillColor(Color.parseColor("#33000040"));
Polygon polygon = mMap.addPolygon(polygonOptions);
ltbounds = builder.build();
arr_ltlngbounds.add(ltbounds);
}
Next I am checking if map center is inside any polygon or not
map.setOnCameraChangeListener(new OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
if (arr_ltlngbounds != null && arr_ltlngbounds.size() > 0) {
for (LatLngBounds l : arr_ltlngbounds) {
if (l.contains(mMap.getCameraPosition().target)) {
snackbar = Snackbar
.make(inflatedView, "Service available here", Snackbar.LENGTH_INDEFINITE)
.setAction("GET", new View.OnClickListener() {
#Override
public void onClick(View view) {
String arr[] = {user_location.latitude + "", user_location.longitude + "", "4"};
new Get_service(activity, A.this, get_service).execute(arr);
}
});
snackbar.show();
break;
}
}
}
}
});
This is my build.gradle just incase
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
multiDexEnabled true
applicationId "com.aaa.bbb"
minSdkVersion 14
targetSdkVersion 23
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile project(':library')
compile 'com.android.support:appcompat-v7:23.1.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.newrelic.agent.android:android-agent:5.3.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.github.jaydeepw:poly-picker:v1.0.22'
compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3'
compile 'com.google.code.gson:gson:2.6.2'
compile 'me.dm7.barcodescanner:zxing:1.8.4'
compile 'com.github.castorflex.smoothprogressbar:library:1.0.0'
compile 'com.github.clans:fab:1.6.2'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.maps.android:android-maps-utils:0.4+'
compile('com.google.api-client:google-api-client-android:1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-drive:v3-rev6-1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.newrelic.agent.android:agent-gradle-plugin:5.3.1"
}
}
repositories {
mavenCentral()
// for downloading polypicker dependency cwac-camera
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
// for downloading poly-picker now we are using jitpack.
// Goodbye Maven Central
maven {
url "https://jitpack.io"
}
}
apply plugin: 'android'
apply plugin: 'newrelic'
dependencies {
compile 'com.android.support:support-v4:22.2.1'
}
android {
useLibrary 'org.apache.http.legacy'
}
The problem about this implementation is, it still shows snackbar (that latlng is inside bounds) even if latlng is outside bounds up to a certain level like there is some buffer area where it will still detect the latlng. I want it to be precise. How can I rectify this?
You can use the PolyUtil.containsLocation method from the Google Maps Android API Utility Library to check if a given location lies inside a polygon represented by a List<LatLng> instead of just checking if the location is in the boundary.
Example:
// Construct a List<LatLng> representing a Polygon
List<LatLng> polygon = new ArrayList<>();
polygon.add(new LatLng(3,0));
polygon.add(new LatLng(3,3));
polygon.add(new LatLng(0,3));
polygon.add(new LatLng(3,0));
// Find the LatLngBounds of the Polygon
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng point : polygon) {
builder.include(point);
}
LatLng test = new LatLng(1,1);
boolean isInsideBoundary = builder.build().contains(test); // true as the test point is inside the boundary
boolean isInside = PolyUtil.containsLocation(test, polygon, true); // false as the test point is outside the polygon