I got following message when I change from Maven to Gradle.
How can I change to using public apis only?
/*
This file was generated by the Gradle 'init' task.
This project uses #Incubating APIs which are subject to change.
*/
build.gradle.kts:
plugins {
java
`maven-publish`
}
repositories {
mavenLocal()
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
}
dependencies {
}
group = "org.example"
version = "1.0-SNAPSHOT"
description = ""
java.sourceCompatibility = JavaVersion.VERSION_1_8
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
Related
I have a multi-module Gradle project which is structured like so:
root
|
|_____main
|
|_____other
This is how the build.gradle.ktss files are structured:
Root:
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0" apply false
kotlin("plugin.spring") version "1.8.0" apply false
kotlin("plugin.lombok") version "1.8.0" apply false
id("org.springframework.boot") version "2.7.2" apply false
id("io.spring.dependency-management") version "1.0.12.RELEASE" apply false
}
subprojects {
apply {
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.kotlin.plugin.spring")
plugin("org.jetbrains.kotlin.plugin.lombok")
plugin("org.springframework.boot")
plugin("io.spring.dependency-management")
}
configurations {
configurations["compileOnly"].extendsFrom(configurations["annotationProcessor"])
all {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
}
}
repositories {
mavenCentral()
}
val implementation by configurations
val testImplementation by configurations
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
implementation("org.springframework.boot:spring-boot-starter")
//other dependencies...
}
configure<DependencyManagementExtension> {
imports {
mavenBom("org.springframework.shell:spring-shell-dependencies:2.1.0")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict", "-Xjvm-default=all")
jvmTarget = "17"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
Main:
import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
`java-test-fixtures`
application
}
group = "my.group"
version = "0.2.0"
java.sourceCompatibility = JavaVersion.VERSION_17
application {
mainClass.set("my.group.MainKt")
}
tasks.withType<BootJar> {
manifest {
attributes["Main-Class"] = "org.springframework.boot.loader.PropertiesLauncher"
}
}
task<JavaExec>("runBootJar") {
val bootJar: BootJar by tasks
classpath = files(bootJar)
debug = true
}
springBoot {
buildInfo()
}
extra["springShellVersion"] = "2.1.0"
dependencies {
implementation("org.springframework.boot:spring-boot-loader")
api("org.springframework.boot:spring-boot-starter-web")
api("org.springframework.boot:spring-boot-starter-batch")
api("org.springframework.boot:spring-boot-starter-data-mongodb")
api("org.springframework.boot:spring-boot-starter-data-jpa")
api("org.springframework.boot:spring-boot-starter-integration")
api("org.springframework.boot:spring-boot-starter-thymeleaf")
api("org.springframework.boot:spring-boot-starter-log4j2")
api("org.springframework.integration:spring-integration-mongodb")
api("org.springframework.boot:spring-boot-starter-mail")
api("org.springframework.shell:spring-shell-starter")
//other dependencies...
}
Other:
plugins {
`java-library`
}
group = "my.group"
version = "0.2.0"
java.sourceCompatibility = JavaVersion.VERSION_17
dependencies {
compileOnly(project(":main"))
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
//other dependencies...
}
As you can see, Main has a dependency towards org.springframework.shell:spring-shell-starter, which in turns makes this piece inside the Root build.gradle.kts mandatory:
configure<DependencyManagementExtension> {
imports {
mavenBom("org.springframework.shell:spring-shell-dependencies:2.1.0")
}
}
If I try to move this part inside the Main script, the following error pops up when I try to compile Other:
Execution failed for task ':other:compileKotlin'.
> Could not resolve all files for configuration ':other:compileClasspath'.
> Could not find org.springframework.shell:spring-shell-starter:.
Required by:
project :other> project :main
Also, if I run Gradle with the stacktrace enabled, there is also this error:
2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)
This made me think there could be some kind of cyclic dependency, but I couldn't find any.
I'd like to move the mavenBom part inside Main because Spring Shell is only used there, and not in every submodule, but in the end I cannot get it working.
What am I missing?
I'm trying to setup a Gradle multi-modules project that will use Quarkus to run the application.
My project structure is as follow
rootFolder
|----produit
|------build.gradle
|----application
|------build.gradle
|--settings.gradle
The root's settings.gradle:
rootProject.name = "proddoc"
include("produit")
include("application")
pluginManagement {
val quarkusPluginVersion: String by settings
val quarkusPluginId: String by settings
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
plugins {
id(quarkusPluginId) version quarkusPluginVersion
}
}
The produit/build.gradle:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.21"
}
repositories {
mavenCentral()
}
val quarkusPlatformVersion: String by project
dependencies {
testImplementation(kotlin("test"))
implementation(enforcedPlatform("io.quarkus:quarkus-vertx:${quarkusPlatformVersion}"))
implementation("io.quarkus:quarkus-vertx")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
The application/build.gradle (generated using the Quarkus CLI):
plugins {
kotlin("jvm") version "1.7.22"
kotlin("plugin.allopen") version "1.7.22"
id("io.quarkus")
}
repositories {
mavenCentral()
mavenLocal()
}
val quarkusPlatformGroupId: String by project
val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project
dependencies {
implementation(enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}"))
implementation("io.quarkus:quarkus-resteasy-reactive")
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-vertx")
implementation("io.quarkus:quarkus-resteasy-reactive-jackson")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.quarkus:quarkus-arc")
testImplementation("io.quarkus:quarkus-junit5")
testImplementation("io.rest-assured:rest-assured")
implementation(project(":produit")) // I just added this
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<Test> {
systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager")
}
allOpen {
annotation("javax.ws.rs.Path")
annotation("javax.enterprise.context.ApplicationScoped")
annotation("io.quarkus.test.junit.QuarkusTest")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
kotlinOptions.javaParameters = true
}
The project compiles when I run a gradle compileJava at the project's root, however when I run a quarkus dev in the application directory, I have the following error:
Project with path ':produit' could not be found in root project 'application'.
I don't know how to make the Quarkus project discover the module outside what it considers to be it's root directory. Any idea?
The answer is pretty simple:
Do not try to run the project (./gradlew quarkusDev) from the application folder but run it from the root's folder
However, an issue remains, related to this issue: https://github.com/quarkusio/quarkus/issues/30748
Quarkus doesn't detect the beans in the produit module in dev mode, but it works fine once the project packaged as a jar.
Im trying to get Proguard to work but Im still new to Gradle.
My build gradle.kts haves an error (Unresolved reference: proguard), I cant create a proguard Task:
plugins {
id("com.github.johnrengelman.shadow") version "5.2.0"
java
kotlin("jvm") version "1.3.61"
}
group = "*...*"
version = "*...*"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
//*...*
implementation("net.sf.proguard","proguard-gradle","6.2.2") //is this correct?
}
configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
jar{
manifest {
attributes["Main-Class"] = "*...*"
}
}
shadowJar{
archiveBaseName.set("*...*")
archiveClassifier.set("")
archiveVersion.set("")
}
register<proguard.gradle.ProGuardTask>("myProguardTask") { //Unresolved reference: proguard
}
}
This is not an Android Project
Because Stackoverflow wants me to write more than just code: Im planing to somehow link the proguard output to the shadowjar task. If you know how to do it Im also interested to that (and I could not try it myself because of this problem).
You declared a dependency of proguard in project rather than for Gradle itself.
Move the dependency to the buildscript block:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.2.2'
}
}
Then you should be able to create your task.
Alternatively, you can declare the repository in settings.gradle.kts:
pluginManagement {
repositories {
jcenter()
}
}
which will trim down the buildscript block in build.gradle.kts:
buildscript {
dependencies {
classpath("net.sf.proguard:proguard-gradle:6.2.2")
}
}
I'm creating gradle multi project for kotlin programming.
When I create dependencies under subprojects in main project build.gradle.kts I'm getting error Configuration with name 'implementation' not found.
Below is my configuration -
plugins {
kotlin("jvm") version "1.3.61" apply false
}
subprojects {
dependencies {
val implementation by configurations
implementation(kotlin("stdlib-jdk8"))
}
}
Once I move the plugins and dependencies into subproject build.gradle.kts then it is working fine.
How can I make dependencies under subprojects work fine?
Code is on github.
With Kotlin dsl, you can add your dependencies as long as you use either apply(plugin = "org.jetbrains.kotlin.jvm") or apply(plugin = "java").
Those needs to be where you put your dependencies { .. }, usually inside a subprojects { .. }.
So here would be a simple build.gradle.kts that would propagate the kotlin dependency in all its subprojects.
plugins {
kotlin("jvm") version "1.3.50"
}
repositories {
mavenCentral()
}
subprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
}
(You would still need to have the kotlin plugin, however no need to specify the version in the other subproject once defined at the root)
Adding the below configuration worked for me
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61")
}
}
subprojects {
apply(plugin = "java")
apply(plugin = "org.jetbrains.kotlin.jvm")
dependencies {
val implementation by configurations
implementation(kotlin("stdlib-jdk8"))
}
}
In your root build.gradle.kts you can also exclude projects if you want:
subprojects {
if (!project.name.contains("ios")) {
apply("${rootDir}/ktlint.gradle.kts")
apply(plugin = "org.jetbrains.kotlinx.kover")
apply(plugin = "com.diffplug.spotless")
}
}
Could you please help me to find a proper way to rename built artifact with Gradle 5 Kotlin DSL
I created a Gradle 5.5.1 Spring Boot 2 project based on Kotlin DSL.
After executing gradle build the built artifact is inside $buildDir/libs folder.
How can I rename it? Let's say I want to give a simple name - app.jar
plugins {
id("java")
id("idea")
id("org.springframework.boot") version "2.1.5.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
}
group = "com.hbv"
version = "1.0.0-SNAPSHOT"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.5.RELEASE")
}
}
the<DependencyManagementExtension>().apply {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:Greenwich.RELEASE"))
implementation("org.springframework.cloud:spring-cloud-starter-config")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-security")
testImplementation("com.h2database", "h2")
testImplementation("org.springframework.boot", "spring-boot-starter-test")
testImplementation("org.springframework.security", "spring-security-test")
}```
Configure the bootJar task which is generating the jar and is a gradle jar task and set its archiveFileName property:
tasks {
bootJar {
archiveFileName.set("app.jar")
}
}
define archiveBaseName in jar task
tasks.withType<Jar> {
archiveBaseName.set("app")
manifest {
attributes["Main-Class"] = application.mainClass
attributes["Implementation-Version"] = archiveVersion
attributes["Implementation-Title"] = "Test for App"
}
}