Spring Boot Can't find main class Multi module - java

I am having difficulties telling Spring the location of the Main class. So far I have only managed to correctly specify where it is when it is in pictures-service module (i.e., pictures-service/src/main/com.bachadiff.application/Application.java)
This is the file structure.
And this is the main gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE")
}
}
plugins {
id 'java'
id 'java-library'
id 'idea'
id "org.springframework.boot" version "2.0.2.RELEASE"
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
bootJar {
baseName = 'com.bachadiff.pictures-service'
version = '0.1.0'
mainClassName = 'com.bachadiff.application.Application'
}
version = '0.1.0'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext.common = [
spring_web : 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE',
spring_rest : 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE',
spring_mongo: 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE',
spring_test : 'org.springframework.boot:spring-boot-starter-test'
]
ext.test = [
junit: 'junit:junit:4.12'
]
dependencies {
api 'org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE'
api 'org.springframework.boot:spring-boot-starter-data-rest:2.0.2.RELEASE'
api 'org.springframework.boot:spring-boot-starter-data-mongodb:2.0.2.RELEASE'
compile project(':pictures-service-impl')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

The mainClassName should consist out of the package and the class name itself, so in your case that should be:
mainClassName = 'com.bachadiff.application.Application'
And since you are saying that you have a multi-project build, you should put this in the build.gradle for the pictures-service-application project

Related

Web3j plugin for gradle task not found

I am beating against a wall for a whole week. I can't really see the reason why it doesn't work. I have a project where I want to run my Java project with the following build.gradle config:
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.3'
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id 'org.web3j' version "4.8.4"
}
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.suplab'
sourceSets {
main {
solidity {
srcDir "contracts"
}
}
test {
solidity {
srcDir "contracts"
}
}
}
ext {
web3jVersion = '4.8.4'
}
npmInstall {
enabled false
}
dependencies {
implementation "org.web3j:core:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate:hibernate-core:5.6.5.Final'
}
I use gradle version 6.8, since it was specified by developer of the plugin. When I try to build this project from the parent, root folder that is the root of the project, it fails with following error:
A problem occurred configuring project ':api'.
> Failed to notify project evaluation listener.
> Task with name 'resolveSolidity' not found in project ':api'.
> Could not create task ':api:generateTestContractWrappers'.
> Task with name 'compileTestSolidity' not found in project ':api'.
I can't figure it out. I checked it against the build that being generated with web3j-cli, and it's the same for the configuration property (both configs have it blank). So, I don't see any reason WHY it fails. Here's the webj3-cli generated build file:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'application'
id "com.github.johnrengelman.shadow" version "5.2.0"
id 'org.web3j' version '4.8.4'
}
group 'org.web3j'
version '0.1.0'
sourceCompatibility = 1.8
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
jcenter()
}
web3j {
generatedPackageName = 'org.web3j.generated.contracts'
excludedContracts = ['Mortal']
}
ext {
web3jVersion = '4.8.4'
logbackVersion = '1.2.3'
}
dependencies {
implementation "org.web3j:core:$web3jVersion",
"ch.qos.logback:logback-core:$logbackVersion",
"ch.qos.logback:logback-classic:$logbackVersion"
implementation "org.web3j:web3j-unit:$web3jVersion"
implementation "org.web3j:web3j-evm:$web3jVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
jar {
manifest {
attributes(
'Main-Class': 'org.web3j.Web3App',
'Multi-Release':'true'
)
}
}
application {
mainClassName = 'org.web3j.Web3App'
}
test {
useJUnitPlatform()
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

Gradle multi-project repository configuration not working for spring-boot application

I have a simple multi-project structure as follows:
|- gps-framework
|- build.gradle
|- settings.gradle
|- gps-web-service
|----build.gradle
|----src/main....
Under the root build.gradle located in gps-framework/ looks like this:
plugins {
id 'java'
id "java-library"
id "maven-publish"
id "jacoco"
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
subprojects {
subproject ->
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
def isApp = subproject.name == 'gps-web-service'
if (isApp) {
apply plugin: 'java'
} else {
apply plugin: 'java-library'
}
group = 'com.mycompnay'
version = project.hasProperty('customVersion') ? project['customVersion'] : 'integration-SNAPSHOT'
//System.out.println(subproject.name)
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
}
compileTestJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
mavenLocal()
maven {
name "release"
url "my-custom-mvn-repo/release"
authentication {
//
}
}
maven {
name "snapshot"
url "my-custoom-mvn-repo/snapshot"
authentication {
//
}
}
}
configurations {
runtime.exclude(group: "org.slf4j", module:"slf4j-log4j12")
}
publishing {
repositories {
maven {
authentication {
//
}
def isSnapshot = subproject.version.contains('SNAPSHOT')
url = isSnapshot ? "my-custom-mvn-repo/snapshot" : "my-custom-mnv-repo/release"
}
}
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}
if (subproject.hasProperty('jacocoTestCoverageVerification')) {
subproject.check.dependsOn subproject.jacocoTestCoverageVerification
}
test {
testLogging {
exceptionFormat = 'full'
}
}
}
The build.gradle of sub-project gps-web-service located in gps-framework/gps-web-service looks like this:
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
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()
}
From what I have read so far, since the repository settings are defined in the root build.gradle and these settings are injected into these subprojects, I do not need to redefine repository settings. This does not appear to be the case as when I run
./gradlew build
The error I get is:
Could not find org.springframework.boot:spring-boot-starter-web:.
Required by:
project :gps-web-service
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Am I misunderstanding the whole concept of injection of project properties or what am I missing here? I will try duplicating the repo settings in the sub-projects build.gradle but was hoping this is not necessary.
To solve this specific problem, I had to define the spring boot plugin in the sub-project's build.gradle as follows:
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
The resulting file looks like this:
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
group = 'com.mycompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
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()
}

Gradle tests not running with javafx project

build.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
mainClassName = 'mvc.Main'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.0-M1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.6.0-M1')
testCompile('org.mockito:mockito-core:3.1.0')
testCompile('com.athaydes.automaton:Automaton:1.3.2')
testCompile("org.testfx:testfx-core:4.0.16-alpha")
testCompile("org.testfx:testfx-junit:4.0.15-alpha")
testImplementation('org.hamcrest:hamcrest:2.2')
implementation 'com.github.cliftonlabs:json-simple:3.1.0'
}
applicationDefaultJvmArgs = [ "-Djdk.gtk.version=2"]
sourceCompatibility = 11
targetCompatibility = 11
test {
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
}
javafx {
modules = ['javafx.controls', 'javafx.fxml']
version = '11.0.2'
}
My project structure is the usual:
src/main/java/mvc/Main.java
src/test/java/mvc/MainTest.java
When I run gradle test or ./gradlew test tests it doesn't execute any tests, not sure what's wrong.
testCompile is no longer a suppored command, you should use testImplementation instead.

spring boot - No auto configuration found in META-INF/spring.factories - gradle

I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.

Spring annotation #Autowired cannot be imported in IntelliJ using gradle

As the title says. I'm using IntelliJ IDEA 2017.1.4
My gradle file is following:
group 'org.ks'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.7.RELEASE"
}
}
apply plugin: "org.springframework.boot"
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
But the attempt to use #Autowired annotation causes compilation error
package app;
import org.springframework.beans.factory.annotation.Autowired;
public class AutowiredCls {
#Autowired
private int app_name;
}
Compiler marks import and #Autowired as errors (red underline)
application.yml:
app.name = autowired_sample
What do I do wrong?
Please add below dependencies, you can refer to this for more details
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
}
It doesn't look like your project has any dependencies at all. (I can see that your buildscript has dependencies... but these will not apply to the project sources thamselves.)
Here is a build.gradle file from a project I once generated using https://start.spring.io:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'soffit-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
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'
}
}
The project itself (my sources) contains 2 dependencies defined for the compile scope:
org.springframework.boot:spring-boot-starter-cache
org.springframework.boot:spring-boot-starter-web
Both of these are Spring dependencies. I imagine that one (or both) of these give my sources access to the #Autowired annotation... either directly or transitively (probably transitively).
FYI - I 've found the solution. It's best to visit start.spring.io to generate gradle.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("junit:junit")
}
gradle.properties:
springVersion=1.5.8.RELEASE

Categories

Resources