Apache Components and Spring Boot - apache

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

Related

Why won't Gradle find my locally published plugin?

I have one project which contains and publishes a Gradle plugin:
plugins {
`java-gradle-plugin`
`kotlin-dsl`
kotlin("jvm") version "1.5.31"
`maven-publish`
}
project.group = "com.company.gradle"
project.version = "1.0.0"
repositories {
mavenCentral()
gradlePluginPortal()
}
gradlePlugin {
plugins.create("pomPlugin") {
id = "com.company.gradle.pom"
implementationClass = "com.company.gradle.pom.PomPlugin"
}
}
Building this and publishing (via ./gradlew publishToMavenLocal) succeeds without errors. After it completes, my local maven repo ~/.m2/reposiory contains:
./com/company/
./com/company/gradle
./com/company/gradle/pom
./com/company/gradle/pom/maven-metadata-local.xml
./com/company/gradle/pom/1.0.0
./com/company/gradle/pom/1.0.0/pom-1.0.0.jar
./com/company/gradle/pom/1.0.0/pom-1.0.0.module
./com/company/gradle/pom/1.0.0/pom-1.0.0.pom
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/maven-metadata-local.xml
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0
./com/company/gradle/pom/com.company.gradle.pom.gradle.plugin/1.0.0/com.company.gradle.pom.gradle.plugin-1.0.0.pom
Then I have another project that tries to use the plugin:
buildscript {
repositories {
mavenLocal()
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
kotlin("jvm") version "1.6.10"
id("com.company.gradle.pom") version "1.0.0"
}
repositories {
google()
mavenCentral()
mavenLocal()
}
but Gradle cannot resolve the plugin:
* What went wrong:
Plugin [id: 'com.foxit.gradle.pom', version: '1.0.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.foxit.gradle.pom:com.foxit.gradle.pom.gradle.plugin:1.0.0')
Searched in the following repositories:
Gradle Central Plugin Repository
Add this at the top of your settings.gradle file in the project where you want to use your plugin.
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
The gradlePluginPortal() bit is for "real" gradle plugins which have been published.
The mavenLocal() bit is for your locally published plugins.
The repositories blocks you have in the build.gradle are for dependencies and not plugins.

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

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.

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