kotlin + gradle+ intellij - no repositories are defined - gradle

anyone can help me out please? i got just project source code and dockefile from ex-colleague without explanation of work but i got in trouble now with time limitation.
please please please.
i got this error message below
Could not determine the dependencies of task ':compileKotlin'.
Could not resolve all files for configuration ':kotlinCompilerClasspath'.
Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.41
because no repositories are defined.
that's my build.gradle below
plugins {
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.3.41"
id "org.jetbrains.kotlin.kapt" version "1.3.41" apply false
id "org.jetbrains.kotlin.plugin.spring" version "1.3.41" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "1.3.41" apply false
id "org.springframework.boot" version "2.1.6.RELEASE" apply false
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
id "com.palantir.docker" version "0.22.1" apply false
}
subprojects {
group = "bawoori"
version = "1.0"
sourceCompatibility = 1.8
apply plugin: "kotlin"
apply plugin: "io.spring.dependency-management"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.41"
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
}

you need add allproject
plugins {
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.3.41"
id "org.jetbrains.kotlin.kapt" version "1.3.41" apply false
id "org.jetbrains.kotlin.plugin.spring" version "1.3.41" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "1.3.41" apply false
id "org.springframework.boot" version "2.1.6.RELEASE" apply false
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
id "com.palantir.docker" version "0.22.1" apply false
}
allprojects {
group = "bawoori"
version = "1.0"
sourceCompatibility = "1.8"
repositories {
mavenCentral()
jcenter()
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = sourceCompatibility
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = sourceCompatibility
}
}
}
subprojects {
apply plugin: "kotlin"
apply plugin: "io.spring.dependency-management"
repositories {
mavenCentral()
jcenter()
}
}

You need to define repository for root Gradle project for the build script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.70"
}
}
plugins {
id "org.jetbrains.kotlin.<...>" version "1.3.70"
}
repositories {
// this repo should be available in every subproject that uses kotlin
mavenCentral() // or jcentrer
}
See Using Gradle section in Kotlin documentation for more information.

Related

Spring boot 2.3.5 | publish jar to local maven repository using gradle is not working

I'm trying to publish a spring-boot project to local maven repository using Gradle. however, I'm getting below error.
My Gradle file looks like below
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven'
}
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
set('springCloudVersion', "Hoxton.SR9")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
Thanks,
I have changed the script to following and still it not working
below is the gradle tasks, error message and script
D:\workspaces\test\common>gradle clean publishToMavenLocal
> Task :publishMavenJavaPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
> Artifact common-1.0.jar wasn't produced by this build.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}
group = 'com.test'
version = '1.0'
ext {
set('springCloudVersion', "Hoxton.SR9")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
repositories {
mavenCentral()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
however if remove dependencies, it's working fine
this script is working
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
}
group = 'com.example'
version = '1.0'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "$buildDir/repos/releases"
def snapshotsRepoUrl = "$buildDir/repos/snapshots"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
any idea why my script is not working ??
Thanks
I removed the org.springframework.boot plugin and used the below method to add dependencies and it worked. I would appreciate if someone can share if there is a document with this information.
this is the change I made
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
to
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.8.RELEASE'
}
and
plugins {
id 'org.springframework.boot' version '2.3.8.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}
to
plugins {
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'java-library'
id 'maven-publish'
}

How to publish an artifact to a remote repository using gradle

I wanted to publish an artifact to a remote repository identified by a url . Here is my build.gradle file. This is a java gradle project with some dependencies. I was able to publish this to a local .m2 repository and make use of this in another project.
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'maven-publish'
}
group = 'com.mob.ci'
version '1.0-SNAPSHOT'
apply plugin: 'maven'
sourceCompatibility = 1.8
repositories {
maven{url 'https://proget1..../maven2/Maven/'}
}
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-couchbase'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = 'https://proget1..../maven2/Maven/'
}
}
}
Here is the update the build.gradle file, that resolved the issue. Thank you #soung for the tip. I need to specify the credentials for accessing the repository.
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'maven-publish'
}
group = 'com.mob.ci'
version '1.0-SNAPSHOT'
apply plugin: 'maven'
sourceCompatibility = 1.8
repositories {
maven{url 'https://proget1..../maven2/Maven/'}
}
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-couchbase'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = 'https://proget1..../maven2/Maven/'
credentials {
username = deployRepoUsername
password = deployRepoPassword
}
}
}
}

kotlin-compiler-embeddable:1.3.61 because no repositories

this keeps me anonying for a day i'm foolish . anyone helps me ?
i got this error message below
Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.61 because no repositories are defined.
that's my build.gradle below
plugins {
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.3.61"
id "org.jetbrains.kotlin.kapt" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.spring" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "1.3.61" apply false
id "org.springframework.boot" version "2.1.6.RELEASE" apply false
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
id "com.palantir.docker" version "0.22.1" apply false
}
subprojects {
group = "bawoori"
version = "1.0"
sourceCompatibility = 1.8
apply plugin: "kotlin"
apply plugin: "io.spring.dependency-management"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
}
you need add allprojects:
plugins {
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.3.61"
id "org.jetbrains.kotlin.kapt" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.spring" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "1.3.61" apply false
id "org.springframework.boot" version "2.1.6.RELEASE" apply false
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
id "com.palantir.docker" version "0.22.1" apply false
}
allprojects {
group = "bawoori"
version = "1.0"
sourceCompatibility = "1.8"
repositories {
mavenCentral()
jcenter()
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = sourceCompatibility
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = sourceCompatibility
}
}
}
subprojects {
apply plugin: "kotlin"
apply plugin: "io.spring.dependency-management"
repositories {
mavenCentral()
jcenter()
}
}
You need to resolve your dependency through jcenter() so add
repositories {
jcenter()
}
to your build.gradle file.
repositories {
jcenter()
}
plugins {
id 'idea'
id "org.jetbrains.kotlin.jvm" version "1.3.61"
id "org.jetbrains.kotlin.kapt" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.spring" version "1.3.61" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "1.3.61" apply false
id "org.springframework.boot" version "2.1.6.RELEASE" apply false
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
id "com.palantir.docker" version "0.22.1" apply false
}
subprojects {
group = "bawoori"
version = "1.0"
sourceCompatibility = 1.8
apply plugin: "kotlin"
apply plugin: "io.spring.dependency-management"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
}

Gradle kotlin in Gradle5.2 Unresolved reference: dependtest

A multi module project with Kotlin source code, which used to work, stops working after upgrading to Gradle 5.2, because the Kotlin classes from the compile project('depend-test') dependency are not found.
Attempted to change plugin version
already viewed https://github.com/gradle/gradle/issues/8980
i defind Test class in project('depend-test')
object Test {
const val test = "123"
}
i want to use Test class in project('test-test')
package com.example.test.controller
import com.example.dependtest.Test
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
#RestController
#RequestMapping
class TestController {
private val log = LoggerFactory.getLogger(TestController::class.java)
#GetMapping(value = ["/test"])
fun test() {
log.info(Test.test)
}
}
when i want to build project('test-test') to jar where i used gradle bootJar。 I get this error:
> Task :test-test:compileKotlin FAILED
e: /Users/houshuai/Documents/dev/demo/test/test-test/src/main/kotlin/com/example/test/controller/TestController.kt: (3, 20): Unresolved reference: dependtest
e: /Users/houshuai/Documents/dev/demo/test/test-test/src/main/kotlin/com/example/test/controller/TestController.kt: (22, 18): Unresolved reference: Test
Expected Behavior
The Kotlin classes in the compile project('depend-test') dependency should be found.
Current Behavior
The Kotlin classes in the compile project('depend-test') dependency are not found:
Try adding this to your build.gradle file
bootJar {
enabled = false
}
jar {
enabled = true
}
Just in case someone else comes across this problem.
I created two modules, test-test and depend-test.
The depend-test project is test-test 's dependency.
I tried to call the parameters of depend-test, but it failed to compile and package.
Env
gradle-5.2.1
Kotlin 1.3.31
Springboot 2.1.4
java 1.8
step one
Edit settings.gradle
rootProject.name = 'demo'
include ":depend-test"
include ":test-test"
project(":depend-test").projectDir = file("depend/depend-test")
project(":test-test").projectDir = file("test/test-test")
I used the 1.3.31 version of the kotlin plug-in. The build.gradle file reads as follows
buildscript {
ext {
kotlinVersion = '1.3.31'
}
repositories {
mavenCentral()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
}
}
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'org.jetbrains.kotlin.jvm' version '1.2.71'
id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71'
}
allprojects {
apply plugin: 'idea'
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: "application"
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven { url "https://plugins.gradle.org/m2/" }
mavenCentral()
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url 'http://maven.springframework.org/release' }
maven { url 'http://maven.springframework.org/milestone' }
}
version = '1.0'
apply plugin: 'io.spring.dependency-management'
group = 'com.mutil.test'
sourceCompatibility = '1.8'
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
}
dependencies {
subprojects.forEach {
archives(it)
}
}
repositories {
mavenCentral()
}
step two
build jar for test-test project ,I used two ways, but the results were the same.
terminal use cmd is ./gradlew :test-test:bootJar
user IDEA gradle tool
result
The class file written by kotlin in the submodule cannot be found.
I do not know if the lack of necessary plug-ins caused the failure to package properly.

Plugin with id 'org.sonarqube' not found

I am trying to implement sonar with gradle for code-coverage measure for my project.
we are using gradle-4.0.1 and sonarqube-6.4 .
when I run gradle sonarqube from command line I get this error-
Plugin with id 'org.sonarqube' not found.
I tried few code changes but no luck, please help.
My build.gradle file is as below-
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.sonarqube'
apply plugin: "jacoco"
apply plugin: "java"
apply plugin: "war"
apply plugin: "org.springframework.boot"
sonarqube {
properties {
property "sonar.projectName","Spring4WebService Code Coverage Demo"
property "sonar.projectKey", "org.sonarqubeJacocoCodeCoverage"
property "sonar.reportPath" , "${project.buildDir}/jacoco/test.exec"
}
}
test{
ignoreFailures = true
}
ext {
jacocoVersion = '0.7.6.201602180812'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main.java.srcDir "src/main/java"
test.java.srcDir "src/test/java"
}
springBoot {
mainClass = "com.concretepage.config.WebAppInitializer"
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web','com.fasterxml.jackson.core:jackson-databind')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
jacoco{
toolVersion = "${jacocoVersion}"
}
jacocoTestReport {
reports{
html.enabled=true
xml.enabled=true
csv.enabled=true
}
}
Just like the 'org.springframework.boot' plugin, the 'org.sonarqube' plugin does not belong to Gradle. It is a third-party plugin, so you need to add it as a buildscript dependency:
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
Now apply plugin: 'org.sonarqube' should work fine.
In my case it looks like:
plugins {
id 'groovy'
id 'application'
id 'org.sonarqube' version '3.0'
}
repositories {
mavenCentral()
}
sonarqube {
properties {
property "sonar.host.url", "http://sonarqube:9000"
property "sonar.sources", "src"
}
}
tasks['sonarqube'].dependsOn test
Using the plugins DSL specifying a full version (e.g., id "org.sonarqube" version "3.5.0.2730" instead of id "org.sonarqube" version "3.5.0") in the plugins section of build.gradle resolved this issue for me.
Here are examples for plugins DSL and legacy plugin application: https://plugins.gradle.org/plugin/org.sonarqube

Resources