How to start up this project using the gradle command line? - gradle

I am following the instruction here https://ktor.io/quickstart/quickstart/gradle.html#intellij-start-a-project to build a simple web server with Netty in Kotlin.
Here is my build.gradle
group 'Example'
buildscript {
ext.kotlin_version = '1.3.61'
ext.ktor_version = '1.3.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'MainKt'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.3"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
I want to be able to start the server up without using IntelliJ.
I have tried
gradle tasks --all
but I cannot find any task that can let me to start up the netty-powered server.
I tried startScripts but it complaints about Deprecated Gradle features
What is the command line to start up the sever? Or do I need to make further changes to the gradle file?

You applied and configured the application plugin therefore the run task is what you're looking for. So:
./gradlew run
should launch your application.

Related

Gradle bootRun from parent folder in multi-module project

I have my Gradle project, which has 2 modules: project A and project B, where the latter depends on the former. Note that both projects are Spring Boot applications, so when I execute gradle bootRun from their respectives directories, they will start fine.
The problem is that I want to start, from parent directory, the service of project A when I execute gradle bootRun, and it is starting project B. It seems that I am missing some Gradle config.
build.gradle (project A)
group = 'com.oni'
version = '0.0.2-SNAPSHOT'
sourceCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile 'org.javassist:javassist:3.18.2-GA'
testCompile("de.flapdoodle.embed:de.flapdoodle.embed.mongo")
}
build.gradle (project B)
group = 'com.oni'
version = '0.0.2-SNAPSHOT'
sourceCompatibility = 1.8
dependencies {
def withoutInflux = { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-data-mongodb' }
compile project(':projectA'), withoutInflux
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.7'
}
build.gradle(parent)
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
// mavenLocal()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter')
testImplementation('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.influxdb:influxdb-java')
compile('org.mockito:mockito-core')
compile('ma.glasnost.orika:orika-core:1.4.2')
compile 'com.google.guava:guava-annotations:r03'
}
}
settings.gradle(parent)
rootProject.name = 'project'
include 'projectA'
include 'projectB'
Thanks in advance.
You can run this by using
./gradlew :projectA:bootRun
./gradlew :projectB:bootRun

Upgrade to spring boot 2.0.6.RELEASE makes tests fail even after downgrade to 2.0.5.RELEASE

I had on my project tests that were 100% green/OK when using springBootVersion=2.0.5.RELEASE.
After I upgraded it to springBootVersion=2.0.6.RELEASE some tests failed.
I downgraded it again to 2.0.5.RELEASE and expected all the tests to be green, but even with ./gradle clean build --no-daemon the tests continue failing.
What might be wrong?
I'm using openjdk-11 (oracle compile).
My gradle.properties:
theSourceCompatibility=1.8
kotlinVersion=1.2.71
springBootVersion=2.0.5.RELEASE
wrapper.gradleVersion=4.10.2
mockkVersion=1.8.9
My build.gradle:
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}"
classpath 'org.jmailen.gradle:kotlinter-gradle:1.16.0'
classpath 'org.owasp:dependency-check-gradle:3.3.1'
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.jmailen.kotlinter'
apply plugin: 'org.owasp.dependencycheck'
apply from: 'versioning.gradle'
group = theGroup
version = getGitTag()
apply from: 'docker.gradle'
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
compile 'org.jetbrains.kotlin:kotlin-reflect'
testCompile "org.jetbrains.kotlin:kotlin-test"
testCompile "org.jetbrains.kotlin:kotlin-test-junit"
compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.3'
runtime 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.springframework.boot:spring-boot-configuration-processor'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.skyscreamer:jsonassert:1.5.0'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
testImplementation "io.mockk:mockk:$mockkVersion"
//TODO: replace mockk line with the following one when we have kotlin 1.3
// testCompile "io.mockk:mockk:1.8.9.kotlin13"
// JUnit 5
testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
testRuntime("org.junit.platform:junit-platform-console:1.2.0")
}
compileKotlin { dependsOn formatKotlin }
defaultTasks 'clean', 'build'
wrapper { distributionType = Wrapper.DistributionType.ALL }

Create plugin for IntelliJ IDEA. Plugin is incompatible with this installation

I create a plugin for IntelliJ IDEA and I want it to run on Android Studio and other products based on IDEA.
I use gradle-intellij-plugin
and have such settings:
build.gradle
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id "org.jetbrains.intellij" version "0.2.17"
id "org.jetbrains.kotlin.jvm" version "1.2.10"
}
group pluginGroup
version pluginVersion
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
apply plugin: 'kotlin'
intellij {
version 'IC-2017.3'
plugins 'git4idea'
pluginName "plugin name"
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
//...
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
plugins.xml
<idea-plugin>
...
<idea-version since-build="143.379"/>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.vcs</depends>
<depends>Git4Idea</depends>
...
</idea-plugin>
On IntelliJ IDEA is installed without errors.
When install on Android Studio 3.0.1 there is an error
Plugin 'plugin name' is incompatible with this installation
How to fix the error?
I met the same problem too and I solved it from plugin.xml , you can also find the solution easily in plugin.xml .
In plugin.xml , you can see this :
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!-- uncomment to enable plugin in all products
<depends>com.intellij.modules.lang</depends>
-->
we can get two links :
http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
I solve the problem by the 1st link , I think the 2nd link is also worth to collect .
Go into the 1st link , and scroll down you will see:
So just change
idea-version since-build="173.0"
to
idea-version since-build="141"
Now you can retry to prepare your plugin .
Сhanged the settings and it works for me
build.gradle
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id "org.jetbrains.intellij" version "0.2.17"
}
group pluginGroup
version pluginVersion
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'idea'
sourceCompatibility = 1.8
targetCompatibility = 1.8
intellij {
version '2017.3'
plugins 'git4idea'
pluginName "plugin name"
updateSinceUntilBuild false
type 'IC'
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.google.code.gson:gson:2.8.2'
compile("com.taskadapter:redmine-java-api:3.1.0") {
exclude group: "org.slf4j"
}
// testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
plugin.xml
<idea-version since-build="141.177"/>
<depends>com.intellij.modules.lang</depends>
<depends>Git4Idea</depends>

Kotlin & Gradle - Make sure you have kotlin-reflect.jar in the classpath

I am working on a app using Kotlin language and Gradle Build in IntelliJ IDEA IDE. I am getting following error:
Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath
at kotlin.jvm.internal.ClassReference.error(ClassReference.kt:86)
at kotlin.jvm.internal.ClassReference.getQualifiedName(ClassReference.kt:26)
at WorkerKt.main(Worker.kt:62)
I have included the dependencies as mentioned in following answer Add kotlin-reflect dependency in gradle
Even I have added the jar file in libs folder but still I am getting above error at runtime.
My Gradle file is as below:
group 'com.working.workerhelp'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Is there something I need to configure for Gradle Build or am I missing something?
add implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" in build.gradle(Module:app)
remove compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" from project level build.gradle

Gradle Eclipse Classpath Exception: FAILURE: Build failed with an exception

I am getting the error as attached in the image above whenever I am trying to run gradle eclipse.
I keep on getting this eclipseClassPath exception.
The Gradle Version, I am using is 3.1
Someone suggested me to use gradle version 2.14 because it won't work with the latest version of gradle.
My build.gradle file is below:
buildscript {
ext {
springBootVersion = '1.2.3.RELEASE'
springCloudConnectorsVersion = '1.2.3.RELEASE'
jarName = 'comOrderAudit'
jarVersion = ' -jar build/libs/app-0.0.1-SNAPSHOT.jar'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.0.RELEASE")
}
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
apply plugin: 'spring-boot'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'jacoco'
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator") {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile "org.springframework.boot:spring-boot-starter-test"
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-aop") {
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
"org.springframework.cloud:Spring-cloud-core:${springCloudConnectorsVersion}"
compile "org.springframework.cloud:spring-cloud-spring-service-connector:${springCloudConnectorsVersion}"
compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector:${springCloudConnectorsVersion}"
compile 'org.codehaus.jettison:jettison:1.3.8'
compile 'com.datastax.cassandra:cassandra-driver-core:2.1.8'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.springframework.boot:spring-boot-starter-log4j2'
compile 'org.springframework:spring-oxm'
compile 'org.simpleframework:simple-xml:2.7.1'
compile 'io.springfox:springfox-swagger2:2.0.0'
compile 'io.springfox:springfox-swagger-ui:2.0.0'
compile 'com.wordnik:swagger-jersey2-jaxrs_2.10:1.3.8'
compile 'com.mangofactory:swagger-springmvc:1.0.2'
compile 'com.datastax.cassandra:cassandra-driver-core:2.1.8'
compile 'com.google.code.gson:gson:2.3.1'
testCompile "junit:junit:4.12"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile 'commons-dbcp:commons-dbcp:1.4'
}
task updateVersion{
Properties props = new Properties()
File propsFile = new File("src/main/resources/application.properties")
props.load(propsFile.newDataInputStream())
println(props.getProperty("buildNumber")+"v")
Integer nextbuildnum = (((props.getProperty("buildNumber")) as Integer) + 1)
props.setProperty('buildNumber', nextbuildnum.toString())
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmmss')
props.setProperty("buildTimeStamp", formattedDate)
props.store(propsFile.newWriter(), null)
props.load(propsFile.newDataInputStream())
}
test {
testLogging {
events 'started', 'passed'
}
jacocoTestReport{
group = "Reporting"
description = "Generate Jacoco coverage reports."
additionalSourceDirs = files(sourceSets.main.java)
reports {
xml.enabled = false
html.enabled = true
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it,
exclude: ['**/model/**'])
})
}
}
}
I found the answer through extensive search.
Looks like the issue was with Spring boot version used in the gradle.
With Gradle version 3.1, the recommended spring boot version is 1.4.x releases.
If I am to use spring boot version 1.2.3 the gradle version I should be using is 2.14.
just changed the spring boot version and the build was success.
For more answers you can take a look at this page here.

Resources