Kotlin Require Library with Gradle Build - gradle

I'm trying to add the library Exposed to my project. So, it leads me to the bintray page where it says to use compile 'org.jetbrains.exposed:exposed:0.8.5'. I open my file build.gradle and place that file into the dependencies segment:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'org.jetbrains.exposed:exposed:0.8.5'
}
IntelliJ auto builds it and I get the following error
Warning:root project 'DB-Table-To-Orm': Unable to build Kotlin
project configuration Details:
java.lang.reflect.InvocationTargetException: null Caused by:
org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration ':compileClasspath'. Caused by:
org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not
find org.jetbrains.exposed:exposed:0.8.5. Searched in the following
locations:
https://repo1.maven.org/maven2/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.pom
https://repo1.maven.org/maven2/org/jetbrains/exposed/exposed/0.8.5/exposed-0.8.5.jar
Required by:
project :
So, I look in the repo and there is no path beyond jetbrains with the exposed directory.
How do I install the Exposed library with Gradle? Do they have the path written down incorrectly? Should I put in a bug report with the project? Or am I just putting the compile statement in the wrong location?
Sorry, if this seems like a silly request, I'm new to Javaland and Kotlin and IntelliJ. Coming for the .NET world.
Update
Here's the build.gradle in its entirety:
group 'com.awebsite.db-table-to-orm'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.4-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'org.jetbrains.exposed:exposed:0.8.5'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

As far as I know Exposed isn't in the main bintray repo (aka jcenter). To make gradle search in Exposed's repo you need to add this:
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
to your repositories section.
Example:
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
}
Then just rebuild and it should work just fine

Related

Could not get unknown property 'enforcer' for extension 'enforce'

I tried to use the gradle plugin 'org.kordamp.gradle.enforcer' but get the error message "Could not get unknown property 'enforcer' for extension 'enforce'" when I start gradle (e.g. ./gradlew clean). I've tried several gradle version (6.9, 7.4, 7.5) and an older version of the plugin (0.9.0).
My project has a simple settings.gradle:
rootProject.name = 'EnforceTest'
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath 'org.kordamp.gradle:enforcer-gradle-plugin:0.10.0'
}
}
apply plugin: 'org.kordamp.gradle.enforcer'
enforce {
rule(ruleType: enforcer.rules.BanDulicateClasses)
}
What is the reason for the error? Any idea is appreciated :-)

Setup kotlin project with gradle

I'm new to kotlin and gradle and tried to set up my very first project:
build.gradle
buildscript {
ext.kotlin_version = '1.0.1-1'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
src\main\kotlin\main.kt
package hello
fun main(args: Array<String>) {
println("Hello World!")
}
And I get the error message "src\main\kotlin\main.kt: (4, 4): Unresolved reference: println".
The build.gradle file I copied from http://kotlinlang.org/docs/reference/using-gradle.html
I'd expect that the standard libraries are included automatically - or do I need to add something here?
I'm using gradle 2.12, JDK 1.8. (in case this matters)
The reference is missing the kotlin-stdlib dependency. It is not added automatically.
kotlin-gradle-plugin buildscript dependency is only Gradle plugin for Kotlin builds, and it doesn't add any dependencies to your project code. In order to use the standard library, one should add it as a dependency.
Append the following to your build.gradle:
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
(jcenter() is needed again, these repositories are different from those in buildscript)

How to configure Gradle to find local SNAPSHOT resource?

I'm trying to do some work with the springfox project which has been broken up into two separate projects: the springfox runtime, and a suite of demos.
In order to investigate the behavior of certain configurations, I need to change the module in springfox/springfox-petstore, and compile that into springfox-demos/springfox-java-swagger.
In springfox, I built and published a new version of springfox-petstore, and validated that it exists correctly in ~/.m2/repository/io/springfox/springfox-petstore/2.2.2-SNAPSHOT.
Next, in springfox-demos I added mavenLocal() as a repository, and added the springfox-petstore-2.2.2-SNAPSHOT as a changing=true dependency.
When I attempt to build the springfox-demos runtime, I get the following error:
* What went wrong:
A problem occurred configuring project ':spring-java-swagger'.
> Could not resolve all dependencies for configuration ':spring-java-swagger:runtimeCopy'.
> Could not find io.springfox:springfox-petstore:2.2.2-SNAPSHOT.
Searched in the following locations:
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
Required by:
springfox-demos:spring-java-swagger:unspecified
I've tried a variety of combinations of build tasks but I can't seem to get Gradle to honor my request for using the local maven repo with a -SNAPSHOT artifact.
Here is the top-level build.gradle:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "com.github.adrianbk:gradle-jvmsrc-plugin:0.6.1"
classpath 'com.ofg:uptodate-gradle-plugin:1.6.0'
}
}
apply from: "$rootDir/gradle/dependencies.gradle"
subprojects {
apply plugin: 'com.github.adrianbk.jvmsrc'
jvmsrc {
packageName "springfoxdemo"
}
apply plugin: 'java'
apply plugin: 'com.ofg.uptodate'
repositories {
jcenter()
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
configurations.all {
//Dont cache snapshots
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
wrapper {
gradleVersion = "2.4"
}
So it appears that the top-level build.gradle can have more than one repositories{} block. I had correctly added the mavenLocal() to one, but missed the other. Once adding the mavenLocal() to the second block, all worked well.

Gradle fails to resolve spring dependency

I am trying to build my project with the following build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.2.1.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
maven {
url 'https://repo.spring.io/milestone'
}
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-mongodb:1.2.2.RELEASE')
compile('org.springframework.data:spring-data-mongodb:1.7.0.RC1')
compile('org.springframework.cloud:spring-cloud-spring-service-connector')
compile('org.springframework.cloud:spring-cloud-cloudfoundry-connector')
compile 'org.springframework:spring-test:4.1.5.RELEASE'
compile 'de.grundid.opendatalab:geojson-jackson:1.3'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.1'
compile 'org.apache.httpcomponents:httpclient:4.4'
testCompile('junit:junit')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
I added the milestone repository because I need the spring-data-mongodb 1.7.0.RC1 dependency. However, there seems to be something wrong with the references of the parent-poms because gradle is unable to fetch the following dependency: org.springframework.data.build:spring-data-parent:1.6.0.RC1
It exits with the following error:
Could not find org.springframework.data.build:spring-data-parent:1.6.0.RC1.
Searched in the following locations:
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo.spring.io/milestone/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.pom
https://repo1.maven.org/maven2/org/springframework/data/build/spring-data-parent/1.6.0.RC1/spring-data-parent-1.6.0.RC1.jar
The output of the gradlew build --debug command can be found here: http://pastebin.com/seYRMFQP
The command additionally produced the following output to stdout: http://pastebin.com/atcWQsKF
I already tried to clean my local gradle cache but it did not resolve the problem.
Sorry for the inconvenience, the artifact is currently misplaced in the release repository, though it should be in milestone.
We'll move it to milestone asap. Until that happens please add the release repository url 'https://repo.spring.io/release' to your build.
seems the repositories you defined in your build do not contain the libraries you're looking for. but it seems the lib is available in jcenter. to add jcenter add the following snippet to your build.gradle file:
repositories {
jcenter()
}
cheers,
René

Android Studio / gradle: "Could not create plugin of type 'LibraryPlugin'"

I have two modules in Android Studio.
Main is the application and Sub is a library module. Sub is referred from Main with compile project(':Sub') in the gradle script. That works when run from Android Studio. But when run from command line, gradlew says:
Could not create plugin of type 'LibraryPlugin'.
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/artifacts/result/ResolvedComponentResult
This is the important parts in Main's build.gradle file:
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
gradleVersion = '1.11'
}
android {
buildToolsVersion '19.0.3'
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile project (':Sub')
}
The Sub gradle file is more or less identical, but has
apply plugin: 'android-library'
instead of 'android'
I have tried with gradle 1.9 and 1.10, but same result.
Anyone knows how to solve this?
Verify that your dependencies contains classpath 'com.android.tools.build:gradle:0.9.+' in each gradle.build file (or just put it in the base one and not declare it in the others). Update gradle/wrapper/gradle-wrapper.properties to point to gradle 1.11:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
If you have any other instances of the gradle-wrapper (such as if you originally made the library project on its own and later added an example app), verify that all instances are updated to point to the same version (each gradle-wrapper.properties file).

Resources