-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin DSL: Can't find imports #98
Comments
This is because we did a refactoring in the version 3.0 which (will be released soon) in which we broke backward compatibility:
The documentation you see is the one of the 3.0 branch which is not yet released. This is because the development branch is master which is also the default branch, and this is not good for users during this transition phase. @deepy, maybe we should try to find a way to avoid that, for instance setting the default branch to 2.x until we release the 3.0 version? This explains why the documentation does not correspond to the binaries you used and why you got these errors, really sorry for that. We did not have any Kotlin example for the 2.x version. It is written in Groovy and not easily usable in Kotlin. However, I am going to try to adapt the example file (which is used in integration tests to ensure it is valid) for the 2.x version in order to help you solve this issue. Another way to solve your issue would be to publish a 3.0 beta version because it sounds like we already did all backward compatibility breaking changes and we have quite a good test coverage so its quality is already quite good. @deepy what do you think about that? I cannot publish a beta version right now (don't have the permission), so I am trying to adapt the Kotlin example to the 2.x and let you know quickly if it succeeded. |
I could successfully convert this file to the version 2.2.3 of the plugin. It is visible here. As you can see, it is less beautiful than the next version, but it works. Hope it will help you and again, sorry for this confusing difference between the project's home page and the latest published binaries. |
Thanks @bsautel, this got me a bit further. I've fixed the imports and now I have the following: val npmInstallTask = tasks.named<NpmInstallTask>("npmInstall")
val buildWeb = tasks.register<NpmTask>("buildNpm") {
dependsOn(npmInstallTask)
setNpmCommand("run", "build")
setArgs(listOf("--prod"))
setWorkingDir(file("${projectDir}/../notes"))
outputs.dir("${buildDir}/resources/static")
outputs.upToDateWhen {
true
}
} However, I get the following error:
I only have the Node.js version configured: node {
version = "12.16.2"
} If I specify more properties, it still fails with the same error: node {
version = "12.16.2"
npmVersion = ""
npmInstallCommand = "install"
distBaseUrl = "https://nodejs.org/dist"
download = false
workDir = file("${buildDir}/node")
npmWorkDir = file("${buildDir}/npm")
} A few questions:
|
You get this error because there is no As I see, you changed the working directory to If this is the case, you should use the Something like: node {
// Other properties if needed
nodeModulesDir = file("${project.projectDir}/../notes")
} You also should remove the overridden Here is the answer to your questions:
Hope this will help you! |
This helped greatly, thanks @bsautel! I have everything compiling now. I found I had to add an extra val buildWeb = tasks.register<NpmTask>("buildNpm") {
dependsOn(npmInstallTask)
setNpmCommand("run", "build")
setArgs(listOf("--", "--prod"))
outputs.dir("${buildDir}/resources/static")
outputs.upToDateWhen {
true
}
} The last issue seems to be the outputs dir. A Also, is this code needed? If I don't change any Angular files between builds, it seems to skip the build regardless of whether I have this code. outputs.upToDateWhen {
true
} |
Yes, using For instance, instead of using And I confirm that you should remove the |
I'm developing an Angular app and most of them have the scripts by default, so there's no additional work to add the scripts. "scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}, I still have a question about the val buildWeb = tasks.register<NpmTask>("buildNpm") {
dependsOn(npmInstallTask)
setNpmCommand("run", "build")
setArgs(listOf("--", "--prod"))
outputs.dir("${buildDir}/resources/static")
} It creates from("${projectDir}/../notes/dist/notes")
into("${buildDir}/resources/static") |
Ok, I see what you mean for npm. I am also using Angular and I use it via npx, but both solutions work. There is an example of an Angular build task here (using the Groovy DSL). What is the output directory of your Angular build (in
So the output dir you set in the Gradle task must be the same as the one configured in the Angular build. |
I got everything working where my projects are side-by-side:
Here's the contents of my build file: import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.moowork.gradle.node.npm.NpmInstallTask
import com.moowork.gradle.node.npm.NpmTask
plugins {
id("se.patrikerdes.use-latest-versions") version "0.2.13"
id("com.github.ben-manes.versions") version "0.28.0"
id("org.springframework.boot") version "2.2.6.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
id("com.github.node-gradle.node") version "2.2.3"
kotlin("jvm") version "1.3.61"
kotlin("plugin.spring") version "1.3.61"
kotlin("plugin.jpa") version "1.3.61"
}
val spa = "${projectDir}/../notes";
node {
version = "12.16.2"
nodeModulesDir = file(spa)
}
group = "com.okta.developer"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-data-rest")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.okta.spring:okta-spring-boot-starter:1.4.0")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
if (project.hasProperty("prod")) {
runtimeOnly("org.postgresql:postgresql")
} else {
runtimeOnly("com.h2database:h2")
}
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
val npmInstallTask = tasks.named<NpmInstallTask>("npmInstall")
val buildWeb = tasks.register<NpmTask>("buildNpm") {
dependsOn(npmInstallTask)
setNpmCommand("run", "build")
setArgs(listOf("--", "--prod"))
}
val profile = if (project.hasProperty("prod")) "prod" else "dev"
tasks.bootRun {
args("--spring.profiles.active=${profile}")
}
tasks.bootJar {
rename("application-${profile}.properties", "application.properties")
if (project.hasProperty("prod")) {
from(buildWeb)
from("${spa}/dist/notes") {
into("static")
}
}
} The issue I'm experiencing now is
|
Ok, nice! And sure you can avoid the task from running when nothing changed! For that you have to declare its inputs and outputs as explained in the Gradle docs. Gradle will be able to check whether inputs and outputs changed or not and will run the task accordingly to that. Have a look to this Angular build example (using the Groovy DSL), it defines the inputs and outputs of the Note that the inputs and outputs of the To know why Gradle considers a task to be up-to-date or not, use the |
Saweeet! You da man, @bsautel!! Here's my final val buildWeb = tasks.register<NpmTask>("buildNpm") {
dependsOn("npmInstall")
setNpmCommand("run", "build")
setArgs(listOf("--", "--prod"))
inputs.dir("${spa}/src")
inputs.dir(fileTree("${spa}/node_modules").exclude("${spa}/.cache"))
outputs.dir("${spa}/dist")
} Results when no files change: ./gradlew bootJar -Pprod
BUILD SUCCESSFUL in 3s
5 actionable tasks: 5 up-to-date
Execution time: 4 s. |
FYI @mraible , I added a Spring Boot Angular example project. |
I'm trying to use this plugin in my Spring Boot project that uses Kotlin for its Gradle file.
I added the imports and plugin as shown in this file.
I also added a
buildWeb
task and madebootJar
depend on it.However, when I try to run it, I get the following error:
I tried running the following, but it doesn't seem to help:
Any idea of what I'm doing wrong?
The text was updated successfully, but these errors were encountered: