MoreTypes class not found - java

I have a java project that is using dagger-2 and grpc, when I try to build it using ./gradlew build I get the following error:
> java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
is MoreTypes supposed to be provided inside of dagger-2 dependencies or I should provide that dependency on the class path?
this is the relevant parts of gradle.build file content:
plugins {
id "net.ltgt.apt" version "0.10"
id "com.google.protobuf" version "0.8.1"
id "java"
}
dependencies {
compile 'io.grpc:grpc-all:1.5.0'
compile 'com.google.dagger:dagger:2.14'
apt 'com.google.dagger:dagger-compiler:2.14'
testApt 'com.google.dagger:dagger-compiler:2.14'
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8

This is a problem in Dagger 2.14 fixed in 2.14.1. See issue 994, "Dagger 2.14 breaks build":
I have not isolated the issue to a small sample project at this point, but a possible cause I see is below, maybe that gives a pointer. I don't have any explicit dependency on Google Auto libs in that part of the build.
java.lang.NoClassDefFoundError: com/google/auto/common/MoreTypes
Confirmed fixed in 2.14.1, which contains this commit.

Related

Gradle plugin must not include version

I have a multiproject gradle project
project_android
project_lib
app
project-lib is in its own git repository which I added to to project_android using git subtree.
I'm stuck. In order to build project_lib by itself, I need to specify a version for this plugin. If I don't have the version
plugins {
id 'org.jetbrains.kotlin.jvm'
}
I get this error when building
* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
```
So I add a version and then it works
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.7.10"
}
But now I can't build project_android, here is the error
Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
> Plugin request for plugin already on the classpath must not include a version
I haven't added this plugin to app so I don't know where it comes from. This is the plugins in project_android/app/build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
// Kotlin Annotation Processing Tool
id 'kotlin-kapt'
// Google Services plugin
id 'com.google.gms.google-services'
// Navigation
id 'androidx.navigation.safeargs.kotlin'
// Performance Monitoring plugin
id 'com.google.firebase.firebase-perf'
}
One project requires me to add a version. Another requires me not to add a version. What do I do to keep both happy?
Usually when I run into this it's because there is another implementation of that plug-in in one of the other gradle files. Look in your build.gradle project file and/or your gradle settings file to see if another version of 'org.jetbrains.kotlin.jvm' is listed. You may have to play around with deleting it from one of those other files and resyncing the gradle until it works.
I resolved this by using the gradle legacy plugin dsl. In project_lib\build.gradle instead of:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.17.10'
}
I instead do this
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
apply plugin: "org.jetbrains.kotlin.jvm"

gradle Failed to apply plugin [id 'org.springframework.boot']

I am trying to run spring-boot project. I have some problem with gradle.
gradle build works fine, but I cannot run gradlew
Cannot run command:
./gradlew build &&java -jar build/libs/gs-spring-boot-docker-0.1.0.jar
Here is error:
Failed to apply plugin [id 'org.springframework.boot']
Spring Boot plugin requires Gradle 4.10 or later. The current version is Gradle 4.9
My gradle version 6.0
My gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
classpath('com.google.cloud.tools.jib:com.google.cloud.tools.jib.gradle.plugin:1.8.0')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.cloud.tools.jib'
bootJar {
baseName = 'gs-spring-boot-docker'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.postgresql:postgresql')
testCompile("org.springframework.boot:spring-boot-starter-test")
}
gradle build works fine, there is no error.
The whole point of the Gradle wrapper is to have a fixed version of Gradle used in a project. This ensures that you don't by accident use an incompatible version than what the project supports. Another benefit is that it automatically downloads the correct version if you don't have it already.
When you type gradle (without the 'w'), you are invoking a manually downloaded distribution that you put on your path. This skips the wrapper part completely. In your case, you have apparently downloaded version 6 and updated the project to work with that version.
However, you have not updated the wrapper scripts, which is what you should have done instead. If you look in gradle/wrapper/gradle-wrapper.properties, you should see that it is set to 4.9, which is no longer compatible with your project.
To update it, you need to run the following command twice:
gradlew wrapper --gradle-version 6.1.1 --distribution-type all (assuming you want version 6.1.1, which is the latest at the time of this writing.)
The first time you run it, it will basically just change the version in gradle-wrapper.properties (e.g to 6.1.1). If this fails because the wrapper is too old compared to the project, just change the file manually with a text editor.
The second time you run it, Gradle will start up using that new version (e.g. 6.1.1) and, if needed, update the wrapper scripts themselves.
Also, if you like to start your Spring Boot application during development, just run gradlew bootRun. No need to build the jar and invoke java manually.
And also, instead of compile, use implementation in your dependencies. The former is deprecated (including testCompile).

IntelliJ IDEA not copying resources on build

My build output is out/production/classes.
Java files get compiled into classes just fine and get put on out/production/classes/[packageName], but resources aren't copied. As far as I know they should go directly inside the out/production/classes directory.
If relevant, I'm using Java 11, Spring Boot and Gradle.
This is my build.gradle
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'net.impfox'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// hidden
}
And my Compiler settings:
What could be the cause for my resources not being copied to the output directory and how can I fix this?
If someone is having this issue in Maven. I fixed it by changing the
<packaging>pom</packaging>
to
<packaging>jar</packaging>
In pom.xml
I copied a pom.xml from a maven moduler project (in main pom.xml it uses pom as packaging). Guess I learned my lesson.
I was not able to find the root problem, but I've got a guess. I renamed the entire project before and replaced every occurence of the old project name with the new one. Maybe some internal cache still had the old name inside?
I ended up cloning the project from version control, now it works.

Make IntelliJ resolve dependencies from modules in same project

Using IntelliJ 2016.2.5, I seem to be unable to make it resolve Gradle dependencies which are in the same project.
Project structure is as follows:
firstModule
-> build.gradle // 1
-> settings.gradle // 2
secondModule
-> build.gradle // 3
-> settings.gradle // 4
Contents of first build.gradle (1):
group 'de.test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {mavenCentral()}
dependencies {}
And settings.gradle (2):
rootProject.name = 'test'
The contents of the second build.gradle (4) are:
group 'de.test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {mavenCentral()}
dependencies {
compile ('de.test:test:1.0-SNAPSHOT')
}
And second settings.gradle (4):
rootProject.name = 'testdep'
Both modules are imported as Gradle projects and are set to auto-import enabled.
I know from maven projects, that IntelliJ - as well as Eclipse - does resolve those dependencies to the respective modules in the project/workspace. But with Gradle it seems to not recognize the dependencies. After every change in the module test I need to run the explicit gradle tasks clean and build before the module testdep seems to pick up the changes. And this process is not even reliable, if I don't change the version. This is most likely because of the gradle caching, but it is annoying, nevertheless.
Using the command line argument --refresh-dependencies is not a real solution because it makes the build times of our project (the one above is only for demo purposes) unbearable. Also, I would love to not having to use the gradle calls explicitly.
Any ideas/improvements how to handle such a situation?
Does it work with Eclipse, any experiences?
Will this be fixed in IntelliJ 2016.3 (I saw some improvements in the gradle area for that release).
What you are trying to do will be possible using the new Composite Builds functionality in Gradle. Support for IntelliJ IDEA is coming soon.

Intellij IDEA can't import Gradle project - "Could not initialize class javax.crypto.SunJCE_b"

I'm working on a Gradle project. The project downloads dependencies and runs perfectly fine when I do gradle run. Here's my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'
mainClassName = 'myProject.MyMainClass'
repositories {
mavenCentral()
}
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.jsoup:jsoup:1.7.2'
testCompile "junit:junit:4.11"
}
jar {
baseName = 'myproject-service'
version = '0.1.0'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
Now I want to import the project in Intellij IDEA.
Import Gradle project >> Use default gradle wrapper (recommended) >> OK
However, when I hit OK it comes up with a dialogue saying:
Could not initialize class javax.crypto.SunJCE_b
Looking in the logs, it says
org.gradle.tooling.GradleConnectionException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
at javax.crypto.KeyGenerator.a(DashoA13*..)
...
2015-03-18 21:31:17,751 [2354198] WARN - nal.AbstractExternalSystemTask - Could not initialize class javax.crypto.SunJCE_b
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not initialize class javax.crypto.SunJCE_b
at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
...
I have no idea how to get this project to work. None of my imports from external repositories work inside IDEA without this (they all appear red). Any help would be appreciated. I'm on:
Intellij IDEA 13.1.6
Java EE 7 (jdk1.7.0_75.jdk)
Gradle 2.3
Mac OS X
SOLUTION:
Still have no idea what the issue is. I tried all the suggestions I could find online and everything I could think of: Install a different version of java, install a different IDEA, try using the original cryptography policy files, try using the unlimited strength policy files and more. None of these worked.
What did work, however, was selecting "Use a local gradle distribution", instead of using the default wrapper. I gave it my gradle install path (/usr/local/gradle-2.3), found by running which gradle (that will give you the path to the executable, namely /usr/local/gradle-2.3/bin/gradle, but I just took the directory part). Now I can build using gradle!!
My best guess is that the gradle plugin installed some other distribution of gradle that wasn't set up properly for my project.
I hope this is helpful to anyone else struggling with using gradle in Intellij IDEA.

Categories