i have problem for setting java environment in windows - java

I have Gradle build like this
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'test.build'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.session:spring-session-core'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
and here my application
package test.build.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
When I build the project, I see there is an error like in this picture:
What is the issue? Is there any error in my Gradle build file?

Looks like you have a missing dependency. Try adding the following dependency:
implementation 'org.springframework.boot:spring-boot-starter'

Related

Annotation Processor Not Running

Project 1 (annotation project):
build.gradle
plugins {
id 'java'
}
apply plugin: 'java'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'
implementation 'com.google.auto.service:auto-service:1.0.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
Annotation
#Target({ElementType.TYPE})
#Retention(RetentionPolicy.RUNTIME)
public #interface Table {
String value();
String[] ignoreColumns() default {};
}
Processor
#AutoService(TableProcessor.class)
#SupportedAnnotationTypes("com.github.ahuangJM.annotations.Table")
#SupportedSourceVersion(SourceVersion.RELEASE_8)
public class TableProcessor extends AbstractProcessor {
#Override
public synchronized void init(ProcessingEnvironment processingEnv) {
System.out.println("init hit!");
super.init(processingEnv);
}
#Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
final Messager messager = processingEnv.getMessager();
messager.printMessage(Diagnostic.Kind.NOTE, "Processing...");
return true;
}
}
\resources\META-INF\javax.annotation.processing.Processor
org.example.processors.TableProcessor
Project 2 (annotation project consumer):
Annotation Consumer
#Table("user-info")
public class UserInfo {
}
build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation files("REDACTED\\code-generator-annotation.jar")
annotationProcessor files("REDACTED\\code-generator-annotation.jar")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
This should be a very simple annotation processor just printing debugging statements.
This all seems correct to me, but process() is not running when I build/run project 2. I have tried overriding getSupportedVersion() and getSupportedAnnotationTypes() as well. That didn't do anything. Also tried without #AutoService, that didn't change anything as well.
EDIT: why am i can getting the print() and/or printMessage() statement?
#AutoService(TableProcessor.class)
should be
#AutoService(Processor.class)
#Retention(RetentionPolicy.RUNTIME)
should be
#Retention(RetentionPolicy.SOURCE)
#AutoService(TableProcessor.class)
should be
#AutoService(AbstractProcessor.class) or #AutoService(Processor.class)
#autoservice(X) means you implement X, but i see a class or interface Processor in your question, so you have to be sure what implement what but your #autoservice first is wrong.

how to develop gradle application using eclipse [duplicate]

I have Gradle build like this
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'test.build'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.session:spring-session-core'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
and here my application
package test.build.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
When I build the project, I see there is an error like in this picture:
What is the issue? Is there any error in my Gradle build file?
Looks like you have a missing dependency. Try adding the following dependency:
implementation 'org.springframework.boot:spring-boot-starter'

Microservice- error in bringing up config server org.springframework.boot.context.properties.bind.BindResult

I'm getting below error when trying to bring up config server. Looks incorrect jar version
any suggestions please
Error
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.cloud.config.server.composite.CompositeEnvironmentBeanFactoryPostProcessor.bindProperties(CompositeEnvironmentBeanFactoryPostProcessor.java:81)
The following method did not exist:
'java.lang.Object org.springframework.boot.context.properties.bind.BindResult.orElseCreate(java.lang.Class)'
The method's class, org.springframework.boot.context.properties.bind.BindResult, is available from the following locations:
*jar:file:/C:/Users/GOPU/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.4.0-M1/503562062a9baee246bb7311526d08d16ae05758/spring-boot-2.4.0-M1.jar!/org/springframework/boot/context/properties/bind/BindResult.class*
The class hierarchy was loaded from the following locations:
org.springframework.boot.context.properties.bind.BindResult: file:/C:/Users/GOPU/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot/2.4.0-M1/503562062a9baee246bb7311526d08d16ae05758/spring-boot-2.4.0-M1.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.boot.context.properties.bind.BindResult
Build.gradle
plugins {
id 'org.springframework.boot' version '2.4.0-M1'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.cloud'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '13'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-config-server'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter'
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Hoxton.RELEASE'
}
}
test {
useJUnitPlatform()
}
Mainfile
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
#EnableConfigServer
#EnableDiscoveryClient
#SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}

Intellij IDEA not generate spring-configuration-metadata-json

I wait that IntelliJ IDEA generates spring-configuration-metadata-json for me.
But it doesn't happen. I read this and this articles and this SO answer and I create a simple spring-boot application:
Gradle file:
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
Property:
#Component
#ConfigurationProperties(value = "test")
public class MyProperties {
private String name;
private int age;
//getters setters
I try to build, rebuild, compile... But IDEA not create this metadata for me. What do I do wrong?

Dagger not generating Component classes

I have tried a great deal debugging this issue but unable to find the cause. Dagger simply doesn't create the DaggerComponent classes. I've checked SO for duplicates but none of the solutions provided worked.
project's build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
jcenter {
url "http://jcenter.bintray.com"
}
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app's build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.hr.crux"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
retrolambda {
jvmArgs '-noverify'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
apt 'com.google.dagger:dagger-compiler:2.2'
compile 'com.google.dagger:dagger:2.2'
provided 'javax.annotation:jsr250-api:1.0'
testCompile 'junit:junit:4.12'
}
HttpModule.java
#Module
public class HttpModule {
#Provides
#Singleton
Retrofit getRetrofit() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://maps.googleapis.com/maps/api/place/")
.build();
return retrofit;
}
}
HttpComponent.java
#Singleton
#Component(modules = {HttpModule.class})
public interface HttpComponent {
void inject(MainActivity activity);
}
Application.java
public class Application extends android.app.Application {
private static Application application;
private HttpComponent appComponent;
#Override
public void onCreate() {
super.onCreate();
application = this;
appComponent = //Cannot find DaggerHttpComponent
}
public static Application getInstance() {
return application;
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Inject
Retrofit retrofit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Dagger is failing to generate the component class in my Application class. I've tried clean building, I've tried invalidating cache but nothing works.
You can start a fresh project by yourself instead of following the tutorial project. If you do so, here is the solution.
These two lines are responsible to generate the compile-time framework in Dagger 2.
compile 'com.google.dagger:dagger:2.14.1'//generates framework in compile time
annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1' //generates framework in compile time based on the annotations you provided.
Full setup Dagger
//dagger 2
compile 'com.google.dagger:dagger:2.14.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1'
//to enable DaggerActivity, DaggerBroadcastReceiver, DaggerFragment etc classes
compile 'com.google.dagger:dagger-android:2.14.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.14.1'
//support libraries with dagger 2
compile 'com.google.dagger:dagger-android-support:2.14.1'
Note: You need to configure Annotation Process as provided in the screenshot below. You can do this File>Other Settings>Default Settings>search"Annotation processor"
As Other threads' Answers does NOT work for me:
I've answered here
Pref -> Editor -> File Types -> Ignore Files And Folders -> Remove "Dagger*.java;"

Categories