I have Ktor project that has a main called Application.kt
.
The layout is like so
.
└── com
└── myProject
├── Application.kt
├── Testing.kt
├── api
│ ├── Routes.kt
│ └── routes
│ ├── NewRoutes.kt
│ ├── OpenApiRoutes.kt
│ └── OldRoutes.kt
├── data
│ ├── Mongo.kt
│ ├── model
│ │ ├── model1
│ │ │ ├── Model1.kt
│ │ └── model2
│ │ ├── Model2.kt
│ └── repository
│ ├── MongoRepository.kt
│ └── Repository.kt
But now I have a script that I would like to run as part of Kubernetes init container, the file looks like this
import com.myProject.data.Mongo
import org.bson.BsonDocument
import org.litote.kmongo.formatJson
class Testing {
suspend fun test() {
return whatever
}
suspend fun test2() {
return whatever2
}
}
suspend fun main() {
val create = Testing()
create.test()
create.test2()
}
i've tried running ./gradlew testing
which I have defined in my build.gradle like so:
task testing( type: JavaExec) {
main = 'com.myProject.Testing'
}
but to no avail, does anybody have any ideas?
When trying to run using the above gradle command i get the error Could not find or load main class Testing
my build.gradle
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
buildscript {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
}
}
task testing( type: JavaExec) {
main = 'com.myProject.Testing'
classpath = sourceSets.main.runtimeClasspath
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
apply plugin: "java"
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'
group 'com.myProject'
version '0.0.1'
mainClassName = "io.ktor.server.netty.EngineMain"
shadowJar {
manifest {
attributes 'Main-Class': mainClassName
}
}
sourceSets {
main.kotlin.srcDirs = main.java.srcDirs = ['src']
test.kotlin.srcDirs = test.java.srcDirs = ['test']
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['testresources']
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://kotlin.bintray.com/ktor' }
}