starting out with ktor and getting random gradle issues, what could be wrong, where to start? - gradle

I'm getting started with KTOR and getting gradle errors with various sample projects...
I tried the Ktor generator and then the KTOR documentation snippet project and both are not building/syncing.
Should I be using IntelliJ Ultimate? (currently I have IntelliJ IDEA 2022.3.2 (Community Edition))
The tutorial-server-get-started gives me: Task 'wrapper' not found in project ':tutorial-server-get-started'.
And the online generated project was giving me something about Plugin [id: 'org.jetbrains.kotlin.jvm', version: '2.2.3'] was not found in any of the following sources:
I tried to find fixes online, but seems like one error leads to another, so maybe I have to start with some specific instructions? Thank you.
Below are the contents of the generated gradle.kts
val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project
plugins {
kotlin("jvm") version "2.2.3"
application
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10"
}
group = "com.example"
version = "0.0.1"
application {
mainClass.set("com.example.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
}
dependencies {
implementation("io.ktor:ktor-network-tls-jvm:$ktor_version")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-websockets:$ktor_version")
implementation("io.ktor:ktor-serialization:$ktor_version")
implementation("io.ktor:ktor-auth:$ktor_version")
implementation("io.ktor:ktor-auth-jwt:$ktor_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
gradlew.properties
ktor_version=1.8.10
kotlin_version=2.2.3
logback_version=1.2.11
kotlin.code.style=official

Related

Gradle7 Version Catalog: How to use it with buildSrc?

I am very excited about the incubating Gradle's version catalogs and have been experimenting with it. I’ve found that the information in my gradle/libs.versions.toml is accessible in the build.gradle.kts scripts for my app and utility-lib projects.
However, I am unable to use the content of the toml file for buildSrc/build.gradle.kts or the convention files.
The only way that I could build was to hard-code the dependencies into those files, as I did before the version catalog feature.
In the buildSrc folder, I created a settings.gradle.kts file and inserted the dependencyResolutionManagement code for versionCatalogs, which is pointing to the same file as for my app and utility-lib projects.
Based on the Gradle7 docs, it seems that sharing a version catalog with buildSrc and modules is possible… I’d appreciate a nudge into getting it to work with buildSrc, if possible.
Here is a simple sample project, which I created via gradle init: my-version-catalog
Thank you for your time and help,
Mike
With Gradle 7.3.3, it is possible. Note version catalogs are GA since Gradle 7.4
The code snippet assumes Gradle is at least 7.4, but if you need them prior that version, insert enableFeaturePreview("VERSION_CATALOGS") at the beginning of each settings.gradle.kts.
Using buildSrc
buildSrc/settings.gradle.kts
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
buildSrc/build.gradle.kts
dependencies {
implementation(libs.gradleplugin.intellij) // <- the lib reference
}
You can even use the version catalog for plugins
gradle/libs.versions.toml
...
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
jetbrains-changelog = { id = "org.jetbrains.changelog", version.ref = "changelog-plugin" }
jetbrains-intellij = { id = "org.jetbrains.intellij", version.ref = "intellij-plugin" }
hierynomus-license = { id = "com.github.hierynomus.license", version.ref = "license-plugin" }
nebula-integtest = { id = "nebula.integtest", version.ref = "nebula-integtest-plugin" }
build.gradle.kts
plugins {
id("java")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.nebula.integtest)
alias(libs.plugins.jetbrains.intellij)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.hierynomus.license)
}
Note for accessing the catalog within scripts, please refer to the below section, the trick is the same.
Using convention plugins and included build
In the main project include a the Gradle project that holds the convention plugins.
build.gradle.kts
includeBuild("convention-plugins") // here it's a subfolder
convention-plugins/settings.gradle.kts
dependencyResolutionManagement {
repositories {
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
rootProject.name = "convention-plugins"
The trick to enable convention plugins to access the version catalog is split in two part, add an ugly implementation dependency that locate where the version catalog generated classes are located.
libs.javaClass.superclass.protectionDomain.codeSource.location
Then in the convention plugin refer to the libs extension via Project::the.
val libs = the<LibrariesForLibs>()
This is tracked by gradle/gradle#15383.
convention-plugins/build.gradle.kts
plugins {
`kotlin-dsl`
}
dependencies {
implementation(libs.gradleplugin.kotlin.jvm)
// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
And in the actual convention plugin
import org.gradle.accessors.dm.LibrariesForLibs
plugins {
id("org.jetbrains.kotlin.jvm")
}
// https://github.com/gradle/gradle/issues/15383
val libs = the<LibrariesForLibs>()
dependencies {
detektPlugins(libs.bundles.kotlinStuff) // access catalog entries
}
The org.gradle.accessors.dm.LibrariesForLibs class is generated by gradle is somewhere in local gradle folder ./gradle/<version>/dependency-accessors/<hash>/classes
Quick note that older IntelliJ IDEA currently (2022.3) reports alias(libs.gradleplugin.thePlugin) as an error in the editor,
although the dependencies are correctly resolved.
This tracked by KTIJ-19369, the ticket indicates this is actually a bug in Gradle Kotlin DSL gradle/gradle#22797, and someone made a simple IntelliJ IDEA plugin to hide this error until resolved.
Brice, it looks like a can of worms to go down that path, particularly for my situation, where I'm trying to use a libs.version.toml file from an android project, but the custom plugin is of course from a java/kotlin project. I tried creating the libs file by hardwiring the path to the toml file in the custom plugin. It might work if both were java projects, but I never tried that since that's not what I'm after. The ideal solution would be for the plugin to use the libs file from the project it is applied to, but it looks like the version catalog needs to be created in the settings file, before you even have access to "Project", so that's why you would have to hardwire the path.
Short answer. No, but there are other techniques for a custom plugin to get project version data from the project it is applied to.

Error when updating XText versions for Gradle 6

I am attempting to update an EMF/XCore project to newer versions to get around a versioning roadblock. Currently the repository that houses this project must target Gradle 4 and Bndtools 4.3 because of problems when targeting newer versions. I readily admit that a problem here is my lack of understanding of XText, XCore, and otherwise. Now I find myself on a machine without access to Java 8 which has forced an attempt to update the project settings if at all possible.
The last safe targets for this project were XText 2.16.0 and org.xtext.builder version 1.0.21. The examples I have been able to locate match the settings of this project for the most part.
So now, attempting to run in a Gradle 6.3 environment with OpenJDK 13 (if the Java version is the issue that can be changed)...
Notes
Some changes are based on researching solutions to my build problem and some comments are added
${mavenURL} is currently pointing to Maven Central
I added the compile platform() line based on XText's Release notes. It does not seem to help this issue, though
I changed version numbers to match those found in the Maven BOM
I have attempted various combinations of changing the org.xtext.builder version as well as targeting both EMF 2.21 and 2.20
I have tried a lower XText version. 2.17.0 fails with a different issue
build.gradle:
plugins {
id 'org.xtext.builder' version '2.0.8'
id 'java' // Helpful? Doesn't appear so
}
repositories {
maven() {
url "${mavenURL}"
}
}
ext.xtextVersion = "2.21.0"
ext.emfVersion = "2.20.0"
dependencies {
compile platform("org.eclipse.xtext:xtext-dev-bom:${xtextVersion}")
xtextLanguages 'org.eclipse.emf:org.eclipse.emf.codegen.ecore.xtext:1.4.0'
xtextLanguages('org.eclipse.emf:org.eclipse.emf.ecore.xcore:1.12.0') {
exclude group: 'org.antlr', module: 'antlr-runtime'
}
xtextLanguages "org.eclipse.xtext:org.eclipse.xtext.ecore:${xtextVersion}"
xtextLanguages "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}"
xtextLanguages 'org.eclipse.emf:org.eclipse.emf.codegen:2.19.0'
xtextLanguages 'org.eclipse.emf:org.eclipse.emf.codegen.ecore:${emfVersion}'
xtextLanguages 'org.eclipse.emf:org.eclipse.emf.mwe2.runtime:2.11.2'
compile "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}"
compile "org.eclipse.xtext:org.eclipse.xtext.xbase:${xtextVersion}"
compile 'org.eclipse.emf:org.eclipse.emf.ecore.xcore.lib:1.4.0'
}
xtext {
version = "${xtextVersion}"
languages {
ecore {
setup = 'org.eclipse.xtext.ecore.EcoreSupport'
}
codegen {
setup = 'org.eclipse.emf.codegen.ecore.xtext.GenModelSupport'
}
xcore {
setup = 'org.eclipse.emf.ecore.xcore.XcoreStandaloneSetup'
generator.outlet.producesJava = true
// Have also tried generator.javaSourceLevel = '1.8'
}
}
sourceSets {
main {
srcDir 'model'
// Move the generated Xcore output to the src directory
output {
dir(xtext.languages.xcore.generator.outlet, 'src-gen')
}
}
}
}
Multiple tries have ended up resulting in the following error:
> ./gradlew jar
...
> Task :com.example.project:generateXtext FAILED
ERROR:A generic type in this context must refer to a classifier or a type parameter (file:...file.xcore)
...
> Xtext validation failed, see build log for details.
for a multitude of lines. The XCore file looks something like this
#GenModel(
complianceLevel="8.0",
loadInitialization="false",
modelDirectory="com.example.project/src-gen",
bundleManifest="false",
updateClasspath="false",
oSGiCompatible="true",
forceOverwrite="true")
#Ecore(
nsPrefix="query",
nsURI="something"
)
// These lines had to be added to resolve the above annotations no longer working
annotation "http://www.eclipse.org/emf/2002/GenModel" as GenModel
annotation "http://www.eclipse.org/emf/2002/Ecore" as Ecore
interface Node wraps an.external.Node {}
abstract class ENode extends Node
{
op Object getParent() // This line fails due to not referring to object or classifier
{
eContainer
}
}
I have seen this error pop up in bug reports on XText sites (such as https://github.com/eclipse/xtext-maven/issues/71), and they were resolved. But generally the projects reference Github examples such as https://github.com/itemis/itemis-blog/tree/xcore_gradle or https://github.com/ghillairet/xcore-gradle-example which both point to versions of XText and the corresponding builder which were indeed working prior to this upgrade attempt.
The project is an XText project. Relevant portion of the .project file is here:
<buildSpec>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>bndtools.core.bndnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
Any help would be appreciated.
I received assistance from the folks working on the XText Gradle plug-in via https://github.com/xtext/xtext-gradle-plugin/issues/171.
The biggest issue is that src-gen cannot exist on the classpath prior to execution of the generateXText task. To assist with this updating the clean task to remove the src-gen folder is recommended. Additionally, the second 3 compile dependencies should be xtextLanguages dependencies.

How can i fix internal server error?HTTP ERROR:500

I`m trying to study kotlin servelet.
Then when I run my project my server does not work well.
This project is created from google-app-engine and use google-cloud-datastore.
How to fix it?
My server displays it.
This is my build.gradle.kts file.
plugins {
val kotlinVersion = "1.3.10"
war
kotlin("jvm") version kotlinVersion
kotlin("kapt") version kotlinVersion
kotlin("plugin.noarg") version kotlinVersion
id("org.asciidoctor.convert") version "1.5.3"
id("com.adarshr.test-logger") version "1.3.1"
confidential
flystore
jacoco
}
apply {
plugin("com.google.cloud.tools.appengine-standard")
}
How can I fix it. please help me.
Thanks.
The main reason is that I have no any permission for google appengine.
So I changed public key on the environment file shell/env.proto.sh.
Setted key is following...
export JWT_PRIVATE_KEY=MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC+zLHlmeg+rpfoQuCCHG6phx0vuP+bfcPTvDz22qvy2hRo1lQms0NSVU/sfFL7CkwQuK40R4IYqeyu4K37EzMa1iGM8clAbVG0Ne/DvuSdqefkXXRgsS3sEbxKtnEmr2EnS8yQEBO7ZbhrAGIuH9piJQqCDTQ/4OfYACcpU8Cx4GiKQG6vSdOGTJLDyHDyobfg/l7wGnwdR/Njw/LAmHCyXpoQg7tMiRODJGLS50GCOIni3LzDD/NWsS6vcvbgZDIcpEyB5eSytzVS4RghQsp4zpkxnpxQ3k5dEf4Y3WueT0DJzxSHqNBU1RvKxKU1pLXy+wb004P8seiUCQB7M7a/AgMBAAECggEBAKnLW90p9AYkNcdaDJV9W/W96flYNxBXAXhiIhbETxUVgegyJD00dorEpRWdJfOGHF8dGtoncN0mCx0tkWbIlUgim0TkvuZ44qbvAOo/7Q9p7pXJnRGXW3ij597NMTDuDhV8XRUvWYABa/a9JqJJcny43fsSaRcXvPr6V99tSyR/OIj4MavQ4Rryn5STLGpiZXuwHQ6kb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Avsyx5ZnoPq6X6ELgghxuqYcdL7j/m33D07w89tqr8toUaNZUJrNDUlVP7HxS+wpMELiuNEeCGKnsruCt+xMzGtYhjPHJQG1RtDXvw77knann5F10YLEt7BG8SrZxJq9hJ0vMkBATu2W4awBiLh/aYiUKgg00P+Dn2AAnKVPAseBoikBur0nThkySw8hw8qG34P5e8Bp8HUfzY8PywJhwsl6aEIO7TIkTgyRi0udBgjiJ4ty8ww/zVrEur3L24GQyHKRMgeXksrc1UuEYIULKeM6ZMZ6cUN5OXRH+GN1rnk9Ayc8Uh6jQVNUbysSlNaS18vsG9NOD/LHolAkAezO2vwIDAQAB
This is very important to use google app-engine.

The DefaultSourceDirectorySet constructor has been deprecated. How to use the ObjectFactory service?

I recently updated to gradle version 5.0-rc-4, and when running ./gradlew assemble (or any other task) I now get the following message:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
When I use ./gradlew assemble --warning-mode all I get:
> Configure project :
The DefaultSourceDirectorySet constructor has been deprecated. This is scheduled to be removed in Gradle 6.0. Please use the ObjectFactory service to create instances of SourceDirectorySet instead.
But in the following build.gradle I don't see where I'm using any DefaultSourceDirectorySet, so what is this warning about, and what would I need to change to be compatible with Gradle 6.0?
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.10'
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
Related
I found create version.txt file in project dir via build.gradle task(gradle 5.0) but I don't have constructs like that so I don't know how it would apply.
I found this deprecation mentioned in the release notes at https://docs.gradle.org/5.0-milestone-1/release-notes.html but they say
In this release of Gradle, the ObjectFactory service, which is part of the public API, now includes a method to create SourceDirectorySet instances. Plugins can now use this method instead of the internal types.
but I don't see how.
I also found the SourceDirectorySet interface at https://docs.gradle.org/current/javadoc/org/gradle/api/file/SourceDirectorySet.html but I don't see how to use it.
Template repository: https://github.com/PHPirates/kotlin-template-project
Update 2019-01-23 Five minutes ago, kotlin 1.3.20 was released and also updated in the Gradle repository so this issue should be solved by updating the Kotlin Gradle plugin to 1.3.20.
Update 2019-01-11 The target version in Youtrack issue KT-26808 has just been updated to 1.3.20. You can view the latest released version in the Gradle repositories here, but at the moment there are still a lot of open issues for 1.3.20.
Update 2018-12-17 The deprecation warning is fixed in commit https://github.com/JetBrains/kotlin/commit/67e82a54e5ee529116e881953f93a4c8f216e33a, the Youtrack issue is closed. Now waiting for a release to roll out.
As #Javaru pointed out, this has already been reported (in september 2018) at Youtrack issue KT-26808.
Using information from Lance's comment in the link that Thomas David Baker pointed to:
Answer:
If you get this warning while you are not using DefaultSourceDirectorySet directly, this is probably coming from a Gradle plugin you use. You could check this using the --warning-mode all --stacktrace flags for the Gradle build, so like ./gradlew assemble --warning-mode all --stacktrace.
In this particular case it's the Kotlin Gradle Plugin, they use it at DefaultKotlinSourceSet.kt#L140-L155:
private val createDefaultSourceDirectorySet: (name: String?, resolver: FileResolver?) -> SourceDirectorySet = run {
val klass = DefaultSourceDirectorySet::class.java
val defaultConstructor = klass.constructorOrNull(String::class.java, FileResolver::class.java)
if (defaultConstructor != null && defaultConstructor.getAnnotation(java.lang.Deprecated::class.java) == null) {
// TODO: drop when gradle < 2.12 are obsolete
{ name, resolver -> defaultConstructor.newInstance(name, resolver) }
} else {
// (code omitted)
}
}
We can trust that they will resolve the issue in time, so don't worry about the warning.

Gradle Unable to run checkstyle

I have a java project on my laptop and I am building it with gradle.
All dependencies are in file system as I am off line most of the time when working on it. They are not too many anyway.
build.gradle:
repositories {
flatDir {
dirs "${rootDir}/lib/main", "${rootDir}/lib/test", "${rootDir}/lib/quality"
}
}
ext.configDir = "${rootDir}/gradle/config"
ext.scriptsDir = "${rootDir}/gradle/scripts"
Now I need to add some quality checks against my code. I was lucky to get PMD checks working but not so lucky with checkstyle. The example from gradle distribution, the gradle in action book I read, the gradle documentation does not seem to be rocket science but I just cant get it to work which become very frustrating, especially that with ant that would have been a five minutes task. Anyway this is my gradle.build entry for checkstyle:
apply from: "${scriptsDir}/checkstyle.gradle"
and this is my checkstyle.gradle (partially shown):
apply plugin: 'checkstyle'
ext.checkstyleConfigDir = new File(configDir, "checkstyle")
ext.checkstyleReportsDir = new File(reportsDir, "checkstyle")
ext.xslStyleFile = new File(checkstyleConfigDir, "checkstyle-noframes.xsl")
checkstyle {
toolVersion = '6.10.1'
configFile = new File(checkstyleConfigDir, 'sun_checks.xml')
ignoreFailures = true
showViolations = true
}
checkstyleMain.doLast {
def main = new File(checkstyleReportsDir, "main.xml")
if (main.exists()) {
ant.xslt(in: main, style: xslStyleFile, out: new File(checkstyleReportsDir, "main.html"))
}
}
dependencies {
checkstyle( 'com.puppycrawl.tools:checkstyle:6.10.1' )
}
However when running my build the checkstyle task fails like below:
* What went wrong:
Execution failed for task ':checkstyleMain'.
> java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.CheckStyleTask
Looking inside the checkstyle-6.10.1.jar I can see there is not such a class as com.puppycrawl.tools.checkstyle.CheckStyleTask but there is one called com.puppycrawl.tools.checkstyle.ant.CheckStyleAntTask instead and I suspect this is the one that gradle should invoke. However I have no idea about how to make gradle invoke that.
The only one suspition I have is that my toolVersion = '6.10.1' is not properly defined and gradle invokes using some default. However all gradle api documentation says about that is this: "String toolVersion The version of the code quality tool to be used."
So what I am doing wrong and how should I fix it.
Thank you in advance for your inputs.
You're running into a bug in Gradle (GRADLE-3314). This issue is fixed in Gradle 2.7 which should be out soon. Would you mind verifying that the issue is resolved with the latest 2.7 release candiate?
You can grab Gradle 2.7-rc-2 from the gradle release candidate landing page.

Resources