Running projects without Eclipse - java

In my company, plenty of teams (including mine) don't know how to run Spring projects without Eclipse to a point that this is becoming a problem. I've extensively searched around for stuff, but stumbling upon places just saying "press Run" for the project to be ran. Many times that doesn't help us understand the dependencies of legacy projects, and of course, legacy projects have no documentation laying around, or the folks who designed it (or the folks who designed it don't know how to run that without the IDE).
Here is the architecture of the latest one:
Spring, Gradle, Java.
I've tried running this project with ./gradlew run, but the task run doesn't seem supposed to run the application, the task doesn't even exist and the build.gradle file doesn't have it.
This is the build.gradle file:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.name'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-actuator'
compileOnly 'org.projectlombok:lombok:1.18.4'
}
This is the Java file that is suppose to be the runner:
package com.company.authApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class AuthApplication {
public static void main(String[] args) {
SpringApplication.run(AuthApplication.class, args);
}
}
Even if the build.gradle file mentiones mavenCentral(), this is not build for Maven at all, that's just the default structure for it.
Any help is appreciated.

Related

Get service and model from another service (module) Gradle

The essence of the problem.
I have several services.
Starter - to start and stop the rest
Service_for_calc - for calculating some operations
Service_sample - service for example
Common_Service-a service for storing models and utils
According to my idea, I will run a starter that will run the rest of the services. Each service will have the same endpoints and models. For example, take the WhoIs functionality.
Each service must tell you who it is.
I don't want to create a model and #Service in every service (module).
I want to create this in Common_service and just import the ready-made logic.
I tried to do this via gradle
to do this in the root settings. gradle I wrote
include 'Service_for_calc'
include 'Common_Service'
include 'Service_sample'
include 'Starter '
and in the service (module) I prescribed it
implementation project(':hub.common')
But I ran into some problem, I can't even describe it clearly, because each time it looked different, but here are the errors that I got when trying to work this way
The module does not see classes from common or does not see the package (despite the fact that the IDE began to suggest them to me)
Some kind of trouble started with the dependency (specifically, Spring dependencies will start working every other time)
Sometimes gradle did not see and threw an error on the implementation project (': hub. common'), with the error that there is no such project ( the name was correct)
After I removed the dependencies, reloaded Gradle and installed it, it worked, but when I tried to open this project on someone else's computer, point 1 was repeated
Maybe I'm doing something wrong, or maybe I shouldn't do it at all.
Is this approach practiced? Was it worth doing it via gradle or should I try it via classpath?
Is it worth doing whole services in a common project?
I will be glad to have a detailed answer!
You have module name conflict, if you have a module named include 'Common_Service' then you should implementation project(':Common_Service')
PS: Here git repo with multi-module, maybe this helps you.
I solve it by root build.gradle
buildscript {
ext {
springBootVersion = '2.4.4'
dependencyManagementVersion = '1.0.11.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
}
}
allprojects {
group = 'omegabi.back.hub'
version = '0.0.1-SNAPSHOT'
}
subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-test'
}
}
project(':hub.sample_service') {
dependencies {
compile project(':hub.common_service')
}
}
I solved this problem by deleting settings.gradle in every project except the root one!

import failed using gradle dependency on windows 10 using IntelliJ

I am following the spring boot documentation https://spring.io/guides/gs/spring-boot/
but after I did the same as in Add Unit Tests step, even though I have the same gradle file, the project will not build because the import failed.
gs-spring-boot\complete\src\main\java\com\example\springboot\HelloControllerTest.java:3: error: package org.hamcrest does not exist
import static org.hamcrest.Matchers.equalTo;
^
error: package org.assertj.core.api does not exist
import static org.assertj.core.api.Assertions.*;
My gradle file content
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
and entire project setup same is given in https://github.com/spring-guides/gs-spring-boot/archive/master.zip
What went wrong here? I have the java SDK setup and I am able to run the http server right before this step. I am on windows 10 using IntelliJ and its built in gradle.
Not sure if this is still a useful answer, but I also ran into this issue.
The problem seems to be that your code is in the 'main' directory instead of the 'test' directory. Moving the test files into the test directory fixed this problem for me.
You're missing Hamcrest:
// https://mvnrepository.com/artifact/org.hamcrest/hamcrest
testImplementation "org.hamcrest:hamcrest:2.2"

IntelliJ IDEA "SpringIO" project reports "unable to make the module..."

I have been using IntelliJ IDEA for Spring Webflux projects, without any issues. Now (using Ultimate 2019.2.1), build/rebuild reports successful completion, but issues warnings that modules are not able to be created and the Gradle project needs to be re-imported.
"Unable to make the module Xxx, related gradle configuration was not found. Please re-import the Gradle project and try again."
I have re-imported the project from the Gradle view, but this does not resolve the warning (i.e., same warning generated by build process).
I have also tried "Invalidate and Restart" to try clearing caches, again without resolving the warnings.
As a "hail Mary", I have uninstalled-and-reinstalled IntelliJ...again without resolving the warnings.
The project was generated as a "SpringIO" within the IDE, and the only dependency identified during generation was on Spring Webflux.
I have attempted to resolve this through JetBrains support (who have been helpful), but JetBrains seems unable to replicate the warnings.
This is the only source file in the project (i.e., the default "main")...
package foo.demo;
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);
}
}
This is the build.gradle being used (although I had not seen the "dependency management" plugin in prior build.gradle files).
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'foo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
It seems that JetBrains latest release (2019.2.1) has one-or-more issues, one of which seems to be the cause for the described behavior. I say "one-or-more issues" because I also discovered that "logging.level" entries in the application.properties file were not being honored by SLF4J/logback.
https://youtrack.jetbrains.com/issue/IDEA-221673

no main manifest attribute, in myFile.jar

I have a problem with the creation of my API jar written in spring.
The problem is that every time I try to run my docker image the error is: "no main manifest attribute, in myFile.jar"
The API must be deployed on my RaspBerry pi
I share a little more details ->
build.gradle
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
group = 'me.myddns.findyourhome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '12'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
springBoot {
mainClassName = 'me.myddns.findyourhome.ApiDispatcher'
}
(me.myddns.findyourhome.ApiDispatcher is the name of the folder of the of the main class, I try to add .MainFileName, but nothing change)
Dockerfile
FROM hypriot/rpi-java
COPY ApiDispatcher.jar .
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "ApiDispatcher.jar"]
I don't know where the error can come from, so if you need some other details to help me, let me know.
thanks in advance!
SOLVED
The problem was that Intellij in the import of the project had confuse some directories. I solved in reimport the project as a gradle project, like a new import!
Hope I can help some one else in my situation :D

How do I set up APT for Immutables such that Intellij Idea will recognize the generated code?

I'm looking into migrating from maven to gradle, in this case, gradle itself seems to be working fine, but Idea isn't recognizing the source code that Immutables is generating.
I've read this blog post on APT, it's how I got this for.
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.3/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java-library'
apply plugin: 'idea'
buildscript {
repositories {
maven {
url 'https://d3vfm0n2cffdwd.cloudfront.net'
}
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'com.xenoterracide:platform:0.1.39-SNAPSHOT'
}
}
repositories {
maven {
url 'https://d3vfm0n2cffdwd.cloudfront.net'
}
jcenter()
}
configurations {
apt
aptCompile
}
// In this section you declare the dependencies for your production and test code
dependencies {
implementation 'com.google.guava:guava'
aptCompile 'org.immutables:value'
compileOnly 'org.immutables:value'
apt 'org.immutables:builder'
// The production code uses the SLF4J logging API at compile time
implementation 'org.slf4j:slf4j-api'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.hamcrest:hamcrest-library'
}
compileJava {
options.annotationProcessorPath = configurations.aptCompile
}
for more code see bitbucket
one of the things that's getting me, is that depending on what I've tried the generated java either ends up in an out directory, or build on the classpath, of course so far neither of these solves the problem.
how do I fix this so that Idea can see the source for the generated types (so that it's not all highlighted in red)?
#CrazyCoder's links helped me get closer to a solution, this seems to resolve it though.
idea {
module {
sourceDirs += file("out/production/classes/generated")
}
}

Categories

Resources