Dokka javadoc jar doesn't work with Intellij IDE - intellij-idea

I have following configuration in build.gradle file:
buildscript {
ext.dokka_version='0.9.15'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
}
}
apply plugin: 'org.jetbrains.dokka'
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/dokkaJavadoc"
}
task packageJavadoc(type: Jar, dependsOn: 'dokkaJavadoc') {
from "$buildDir/dokkaJavadoc"
classifier = 'javadoc'
}
artifacts {
archives packageJavadoc
}
This generates properly looking javadoc jar ("${moduleName}-javadoc.jar"). However when imported with Intellij Idea, while it is detected as javdoc jar, IDE support doesn't work. Is it format incompatibility with dokka-javadoc or gradle misconfiguration?

Related

(KotlinSourceSet with name 'androidMain' not found.) How can I add android as a build target to a Kotlin Multiplatform project

I am trying to add android() as a build target to a Kotlin Multiplatform library so that I can add a specific library for the android target. All the other targets (jvm, linux, ios) work fine, but android seems to have issues, because the KotlinSourceSet is not being create like the others.
That's where I get the error:
KotlinSourceSet with name 'androidMain' not found.
I wonder, do I have to add the SourceSet manually? Am I missing some crucial build step?
Here is my gradle.build.kts
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
}
buildscript {
repositories {
google()
}
dependencies {
classpath ("com.android.tools.build:gradle:4.2.2")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
}
group = "zzz.xxxx"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
kotlin {
jvm()
linuxX64("linux")
ios()
android()
sourceSets {
val commonMain by getting {
dependencies {
implementation("...")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation("...")
}
}
val androidMain by getting {
dependencies {
implementation ("...")
}
}
val jvmTest by getting
}
}
I tried adding a androidMain folder, but it is not getting recognized as a KotlinSourceSet. Non of the resources online seem to help either.
To add android as a build target your need to setup android-gradle-plugin first.
With example setting of android plugin gradle.build.kts will be:
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
id("com.android.library") version "7.3.0" // (1) add plugin
}
//...
// (2) setup plugin
android {
compileSdk = 33
defaultConfig {
minSdk = 24
multiDexEnabled = true
}
sourceSets {
getByName("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
}
}
UPDATE
Before you are adding Android Gradle plugin:
Check that Google Maven repository is listed in your settings.gradle(.kts) file
Check the Android Gradle plugin is added to the project build.gradle(.kts) file
Check the Android Gradle plugin is compatible with your Gradle version

Difficulty moving Gradle configuration to an external script

I am trying to move some parts of my Gradle build script to an external configuration file that can be shared among projects. Here is an example with the Detekt plugin:
Current Code
build.gradle.kts (condensed to only the relevant parts)
plugins{
id("io.gitlab.arturbosch.detekt").version("1.19.0-RC1")
}
...
detekt{
...
}
What I'm trying to do
build.gradle.kts
apply(File("common.gradle.kts"))
common.gradle.kts
plugins {
id("io.gitlab.arturbosch.detekt").version("1.19.0-RC1")
}
detekt{
...
}
but when I do this I get this error:
<my_project>\common.gradle.kts:7:1: Unresolved reference: detekt
So the plugin section doesn't appear to be doing anything. And just to be clear, this plugin does not need anything in dependencies section, it works fine inside build.gradle.kts with only the plugin declaration.
Why doesn't this work?
I am using it with normal Groovy Gradle scripts like this:
# detekt.gradle
apply plugin: 'io.gitlab.arturbosch.detekt'
tasks.detekt.jvmTarget = "1.8"
detekt {
buildUponDefaultConfig = true
input = files("${rootProject.projectDir}/app/src")
config = files("${rootProject.projectDir}/detekt.yml")
reports {
html.enabled = true
xml.enabled = true
}
}
# build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath libs.android.gradle
classpath libs.kotlin.gradle
classpath libs.detekt
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
subprojects {
apply from: rootProject.file('detekt.gradle')
apply from: rootProject.file('ktlint.gradle')
apply from: rootProject.file('spotless.gradle')
...
}

kotlin-compiler-embeddable missing within gradle build

I am trying to setup a multiproject gradle/kotlin build and I am getting following error:
Could not determine the dependencies of task ':compileKotlin'.
> Could not resolve all files for configuration ':kotlinCompilerClasspath'.
> Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10 because no repositories are defined.
Required by:
project :
Strange thing is the empty project :.
My simplifiged build.gradle.kts looks like this:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
base
kotlin("jvm") version "1.4.10"
}
buildscript {
extra["kotlin_version"] = "1.4.10"
repositories {
jcenter()
mavenCentral()
}
}
subprojects {
apply(plugin = "kotlin")
repositories {
jcenter()
mavenCentral()
}
tasks.compileKotlin {
kotlinOptions.jvmTarget = "11"
}
tasks.compileTestKotlin {
kotlinOptions.jvmTarget = "11"
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:${rootProject.extra["kotlin_version"]}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.extra["kotlin_version"]}")
}
}
Do I need to duplicate the repositories within the buildscript section?
What is that is causing the error above?
It seems like your repositories { ... } configuration done in the subproject section is sufficient, but it is only applied to the supbrojects but not the root project itself (which has the Kotlin plugin applied, too, and whose task :compileKotlin is failing).
There are two ways to fix this.
First, you could move the repositories { ... } section from subprojects { ... } to a new block allprojects { ... } (thus applied to the root project as well).
Or, if you don't actually need the Kotlin plugin in the root project (i.e. you don't have Kotlin code there), you can add .apply(false) to your plugin declaration:
plugins {
kotlin("jvm").version("1.4.10").apply(false)
}

taskdef class com.sun.tools.xjc.XJCTask cannot be found

I am trying to generate classes from an XSD file in a Springboot project with multiple modules. I tried to follow the guide given here.
I have the below config in my root build.gradle
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
maven { url "https://mvnrepository.com/artifact" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
//####################### XJC - JDK 1.7/1.8 ####################
classpath 'com.github.jacobono:gradle-jaxb-plugin:1.3.5'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
//####################### XJC - JDK 1.7/1.8 ####################
apply plugin: 'com.github.jacobono.jaxb'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
maven { url "https://mvnrepository.com/artifact" }
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
}
and below config in my module's build.gradle
dependencies {
compile project(':appCommon')
compile("org.springframework.boot:spring-boot-starter")
}
//####################### XJC - JDK 1.7/1.8 ####################
jaxb {
xjc {
xsdDir = "schemas/v1.1"
generatePackage = "com.test.domain.v1_1"
}
}
when I run the xjc task from my IntelliJ on my module, I am getting an exception as below
taskdef class com.sun.tools.xjc.XJCTask cannot be found
using the classloader AntClassLoader[]
Any help with what is going wrong is appreciated
Looks like you're missing the jaxb dependencies. In your module's build.gradle add the following:
dependencies {
jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41'
jaxb 'com.sun.xml.bind:jaxb-impl:2.2.7-b41'
jaxb 'javax.xml.bind:jaxb-api:2.2.7'
}

Can't find spock inside of intellij

I am pretty new to intellij and spock.
I am adding spock testing to my spring boot project using gradle. Here's my build.gradle:
buildscript {
ext {
springBootVersion = '1.4.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'theta-server'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.spockframework:spock-core:1.0-groovy-2.4')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
And so I added a spock test such:
package com.heavyweightsoftware.theta.server.controller
/**
*
*/
class ThetaControllerTest extends spock.lang.Specification {
def "Theta"() {
}
}
But I can't run the test inside my intellij environment because it says "cannot resolve symbol 'spock'"
The build runs fine directly.
At times, IJ may not update the project classpath after some changes. It seems that this happens for both Maven POM files as well as Gradle build files. Usually, this is easily solved by forcing a sync with the Reimport all gradle/maven projects button from the appropriate tool window (maven, gradle):