taskdef class com.sun.tools.xjc.XJCTask cannot be found - intellij-idea

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'
}

Related

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')
...
}

maven-publish missing artifact to repository

II'm trying to publish my lib but i'm having some problems related to its publication.
I'm using this library https://github.com/vanniktech/gradle-maven-publish-plugin to publish my project on maven central (oss), but, this for some reason only -sources.jar, -javadoc.jar and .module are being pushed to the repository, however file-butler-0.1.4-SNAPSHOT.jar is missing :(
Does someone have any idea?
build.gradle(module)
plugins {
id 'java-library'
id 'kotlin'
id 'kotlin-kapt'
}
dependencies {
def gson = "com.google.code.gson:gson:2.8.6"
def moshi = "com.squareup.moshi:moshi:1.11.0"
def moshCodeGen = "com.squareup.moshi:moshi-kotlin-codegen:1.11.0"
implementation(Deps.core.kotlin)
implementation(gson)
implementation(moshi)
kapt(moshCodeGen)
testImplementation(Deps.testing.truth)
testImplementation(Deps.testing.jUnit)
kaptTest(moshCodeGen)
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
main.java.srcDirs += 'src/main/java'
}
apply plugin: "com.vanniktech.maven.publish"
build.gradle.kts(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath(kotlin("gradle-plugin", "1.4.10"))
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.4.10")
classpath("com.vanniktech:gradle-maven-publish-plugin:0.13.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}
task<Delete>("clean") {
delete(rootProject.buildDir)
}
ps: publishToMavenLocal publish the expected jar to my local repository.

Unable to resolve dependency for :Could not resolve org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.8.1-rc13

I am getting a gradle build error for unresolved dependencies in a Kotlin/Native sample project.
Failed to resolve: org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.8.1-rc13
my build.gradle (common module) looks like
apply plugin: 'kotlin-platform-common'
apply plugin: 'kotlinx-serialization'
repositories {
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
jcenter{ url "https://jitpack.io" }
jcenter()
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
}
Build.gradle(platform-android level)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.phonepe.mykotlinnativesample"
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
def butterknife_version = '8.8.1'
repositories{
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
jcenter{ url "https://jitpack.io" }
jcenter()
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "com.jakewharton:butterknife:$butterknife_version"
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16' // if you use the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.android.support:exifinterface:27.1.1'
expectedBy project(":common")
}
Project level Build.gradle looks like:
apply plugin: 'kotlinx-serialization'
buildscript {
ext.kotlin_version = '1.3.0-rc-131'
ext.serialization_version = '0.8.1-rc13'
ext.serializationRepo = "https://dl.bintray.com/kotlin/kotlinx/"
ext.serialization_plugin_version="1.3.0-rc-131"
repositories {
google()
jcenter()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.9.2"
classpath "org.jetbrains.kotlin:kotlin-serialization:$serialization_plugin_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
}
}
repositories {
google()
jcenter()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle::
include ':android', ':common', ':myapplication'
enableFeaturePreview('GRADLE_METADATA')
What are the correct versions and repositories that I can use to be able to use serialization?
Setup you've attached is kinda strange, because you're applying Kotlin/Native's 'konan' plugin to the same module as 'kotlin-platform-common' plugin. First of all, 'konan' is deprecated and replaced with 'kotlin-platform-native'. Secondly, these plugins should be applied to different gradle modules, see kotlin multiplatform reference.
Regarding serialization, it now comes in two flavours: One, for Kotlin 1.2 has version numbers 0.6.x (0.6.2 for 1.2.70) and does not support Kotlin/Native; only separate json parser is provided instead. Second flavour, for Kotlin 1.3 is under development phase and has number 0.8.x-rc13 (latest one is 0.8.1-rc13 for Kotlin/Native 0.9.2) and it does contain K/N support in a separate artifact with coordinates "kotlinx-serialization-runtime-native". Serialization docs for Kotlin 1.3 preview reveal more information: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/eap13.md .
There is also a dedicated example of setup which contains a ready-to-use stub of multiplatform project with serialization. Branch native_preview uses aforementioned Kotlin 1.3-rc, K/N 0.9.2 and serialization 0.8.1.

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):

Apache Components and Spring Boot

I am trying to include the latest version of the apache httpclient libraries in my spring boot application. When I try to compile the app I get a bunch of package does not exist / cannot find symbol.
ex. error: package org.apache.http does not exist
ex. error: package org.apache.http.client.config does not exist
ex. error: package org.apache.http.conn.socket does not exist
ex. class HttpContext cannot find symbol
Below are the relevant parts of my build.gradle
buildscript {
repositories {
maven { url "https://repo.spring.io/libs-release" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
//excluding a particular transitive dependency:
exclude group: 'commons-logging' //by group
exclude group: 'ch.qos.logback' //by group
}
compile 'org.apache.httpcomponents:httpclient:4.4'
compile 'org.apache.httpcomponents:httpcore:4.4'
compile 'org.apache.httpcomponents:httpmime:4.4.1'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
Any idea why id doesn't seem to be able to find the classes?
Thanks,
Nathan