I have created a relatively new project with 4 modules inside one project (created with intelij). However, I have now got to the stage where I want to import one module (:domain) from another (app-updater). The issue I'm facing is when I do this from within intelij it gives me errors in the "Build: Sync" tab. This is strange since my module app-updater is able to reference to module domain when I add the line "compile project(':domain')" into build.gradle and when I remove the line I get issues with the class being missing so the build: sync seems to be working it's just running it from inside intelij seems to give an error saying "Project with path ':domain' could not be found in root project 'app-updater'." I have attached my gradle config below, hopefully I have given enough info but if not feel free to ask for more, thanks for any help.
Main project settings.gradle file
rootProject.name = 'rGuide'
include 'domain'
include 'service'
include 'app-updater'
include 'app-rest'
:domain build.gradle
group 'domain'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.9'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
app-updater build.gradle file
group 'app-updater'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
google()
maven {
url 'https://repo.spring.io/plugins-release/'
}
maven {
url 'https://repo.spring.io/milestone'
}
}
dependencies {
compile project(':domain')
// https://mvnrepository.com
compile group: 'net.ser1', name: 'gozirra-client', version: '0.4.1'
compile group: 'io.netty', name: 'netty-all', version: '4.1.36.Final'
compile group: 'io.projectreactor.netty', name: 'reactor-netty', version: '0.9.0.M2'
compile group: 'org.springframework.integration', name: 'spring-integration-stomp', version: '5.1.6.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-core', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '5.1.6.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
TLDR - Trying to import domain into app-updater within intelij, it "works fine" and seems to import domain however when I do this with the Build: sync tab in intelij it gives an error saying "Project with path ':domain' could not be found in root project 'app-updater'.". Thanks for any help!!
Related
I'm facing this error while running the project. I'm unable to know the cause of the error and unable to find a solution online as well.
This project is running over another laptop without any error but when I extracted the zip and tried to run it, found it throwing error.
Please help me figure this out. Thanks
Error
Execution failed for task ':Application.main()'.
Process 'command '/home/jamshaid/Documents/idea-IC-192.5728.98/jbr/bin/java'' finished with non-zero exit value 1
StackTrace
2019-08-11 09:57:06,589 2269 [main] INFO com.techno.homes.Application - No active profile set, falling back to default profiles: default
2019-08-11 09:57:06,628 2308 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.AbstractMethodError: Receiver class org.springframework.cloud.bootstrap.BootstrapApplicationListener$CloseContextOnFailureApplicationListener does not define or inherit an implementation of the resolved method abstract getOrder()I of interface org.springframework.core.Ordered.
at org.springframework.core.OrderComparator.findOrder(OrderComparator.java:142)
at org.springframework.core.annotation.AnnotationAwareOrderComparator.findOrder(AnnotationAwareOrderComparator.java:65)
at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:125)
at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:113)
at org.springframework.core.OrderComparator.doCompare(OrderComparator.java:82)
at org.springframework.core.OrderComparator.compare(OrderComparator.java:68)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:360)
at java.base/java.util.TimSort.sort(TimSort.java:220)
at java.base/java.util.Arrays.sort(Arrays.java:1515)
at java.base/java.util.ArrayList.sort(ArrayList.java:1749)
at org.springframework.boot.SpringApplication.asUnmodifiableOrderedSet(SpringApplication.java:1325)
at org.springframework.boot.SpringApplication.getListeners(SpringApplication.java:1234)
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:66)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:394)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:328)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.techno.homes.Application.main(Application.java:24)
Gradle File
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
apply plugin: 'docker'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'}
buildscript {
project.ext {
springBootVersion = '2.0.4.RELEASE'
jarName = 'recipe'
versionName = '1.0.0'
gradleDockerVersion = '1.2'
swagger2version = '2.9.2'
}
repositories {
jcenter()
maven { url "https://repo.maven.apache.org/maven2" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle- plugin:${project.springBootVersion}"
classpath "se.transmode.gradle:gradle-docker:${project.gradleDockerVersion}"
}
}
task createWrapper(type: Wrapper) {
gradleVersion = '4.4.1'
}
// Used by the Docker gradle plugin, group refers to the account under which the docker image is created
group = 'com.techno.homes'
mainClassName = 'com.techno.homes.Application'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
jcenter()
}
ext {
springCloudVersion = 'Greenwich.SR2'
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.0.4.RELEASE'
compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.16.Final'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web-services', version: '2.0.4.RELEASE'
compile group: 'ma.glasnost.orika', name: 'orika-core', version: '1.4.6'
compile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.springframework.boot', name: 'spring-boot-test-autoconfigure', version: '2.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version: '5.1.8.RELEASE'
compile(group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.4.3.Final')
compile(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final')
compile group: 'org.springframework.boot', name: 'spring-boot-test'
compile group: 'org.mockito', name: 'mockito-core', version: '2.15.0'
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.4'
compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.4'
compile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.4'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '2.0.1'
compile group: 'com.spotify', name: 'docker-maven-plugin', version: '1.2.0'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'
runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.46'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version: '1.58'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
// Basic Spring boot with config client
// compile('org.springframework.cloud:spring-cloud-starter-config')
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
// Spring OAuth2 security
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.security.oauth:spring-security-oauth2")
// compile("org.springframework.security:spring-security-jwt")
compile group: 'org.springframework.security', name: 'spring-security-jwt', version: '1.0.10.RELEASE'
// Eureka client
// compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version: '2.0.0.RELEASE'
// Zipkin tracing
//compile('org.springframework.cloud:spring-cloud-starter-zipkin')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin', version: '2.1.2.RELEASE'
// Swagger for API testing
compile("io.springfox:springfox-swagger2:${swagger2version}")
compile("io.springfox:springfox-swagger-ui:${swagger2version}")
compile group: 'org.springframework.security', name: 'spring-security-core', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-config', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-web', version: '5.1.5.RELEASE'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.3.6.RELEASE'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
//camel
compile group: 'org.apache.camel', name: 'camel-spring-boot', version: '2.15.1'
compile group: 'org.apache.camel', name: 'camel-pulsar', version: '2.24.1'
compile group: 'org.apache.camel', name: 'camel-core', version: '2.24.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9.3'
}
jar {
baseName = "${project.jarName}"
version = "${project.versionName}"
enabled = true
manifest {
attributes 'Main-Class': 'com.techno.homes.Application'
}
}
Allication
#Configuration
#EnableJpaAuditing
#EnableJpaRepositories("com.techno.homes.repositories")
#SpringBootApplication
#EnableEurekaClient
#EnableResourceServer
#EnableSwagger2
#EnableOAuth2Client
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Your Spring Boot version is too old for your Spring Cloud version:
https://github.com/spring-cloud/spring-cloud-commons/issues/552
Spring Cloud Greenwich (2.1.x) is not compatible with spring boot 2.0.x and spring framework 5.0.x. Either update spring boot or downgrade spring cloud to Finchley.
So please update Spring Boot to 2.1.x
PS: searching on 'BootstrapApplicationListener$CloseContextOnFailureApplicationListener' would have lead you there straight away :-)
Ok - did some testing here.
Created empty SpringBoot application from start.spring.io.
Imported the project into IntelliJ.
I then loaded your gradle file contents. Also started by removing all the # imports in the main (Application) class - just kept #SpringBootApplication.
Removed all the other classes (including tests).
Had same error.
Started by removing all the gradle dependencies for Swagger and Hibernate, etc. Those are not required to get a bare-bones SpringBoot app running.
Removing this line solved to error (not throwing the error anymore):
compile("org.springframework.security.oauth:spring-security-oauth2")
So something needs to be configured if you want to do Spring OAuth2 ... for you to find.
Suggest you add small building blocks at a time - you have a lot of stuff in the SpringBoot main app annotated. Spring will auto-configure defaults for all it can, but you might run into similar problems.
Add one annotation - write unit test class that will verify basic functionality of that specific annotation. Then enable the next one, write unit test.... unit all are working with basic test coverage.
This is because of spring and cloud version not compatible.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath />
</parent>
The version of the parent should be an upgrade one or the same as cloud version.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
My byild.gradle file
Able to export jar with JAVA 8. when I configure to JAVA 11 exported jar doesn't contain external jars
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
}
configurations
{
all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12' //by both name and group
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
compile group: 'com.microsoft', name: 'sqljdbc4', version: '3.0'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
compile group: 'com.ibatis', name: 'ibatis2-common', version: '2.1.7.597'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.json', name: 'json', version: '20171018'
compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13'
compile group: 'com.itextpdf.tool', name: 'xmlworker', version: '5.5.13'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.2'
}
add this below lines into your build.gradle
jar { manifest {attributes "Main-Class": "your main class" } from {configurations.compile.collect { it.isDirectory()? it : zipTree(it) } }
then do a clean/build,
the jar created in \build\libs folder is your runnable jar
I am using gradle to compile my Groovy and Java code. today I update my groovy 2.5.4 and upgrade gradle to version 5.
gradle run command failing now with this error message.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Could not resolve all files for configuration ':detachedConfiguration1'.
> Could not find org.codehaus.groovy:groovy:1.0.0.
Searched in the following locations:
- https://jcenter.bintray.com/org/codehaus/groovy/groovy/1.0.0/groovy-1.0.0.pom
- https://jcenter.bintray.com/org/codehaus/groovy/groovy/1.0.0/groovy-1.0.0.jar
- http://repository.apache.org/snapshots/org/codehaus/groovy/groovy/1.0.0/groovy-1.0.0.pom
- http://repository.apache.org/snapshots/org/codehaus/groovy/groovy/1.0.0/groovy-1.0.0.jar
Required by:
project :
* Try:
Here is the build.gradle file.
plugins {
id 'groovy'
id 'application'
}
repositories {
jcenter()
maven {
url "http://repository.apache.org/snapshots/"
}
}
dependencies {
// Use the latest Groovy version for building this library
implementation 'org.codehaus.groovy:groovy-all:2.5.4'
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.6.1'
compile group: 'org.apache.directory', name: 'groovyldap', version: '0.1-SNAPSHOT'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
// https://mvnrepository.com/artifact/org.apache.directory.shared/shared-ldif
compile group: 'org.apache.directory.shared', name: 'shared-ldif', version: '0.9.19'
// https://mvnrepository.com/artifact/org.apache.directory.api/api-ldap-model
compile group: 'org.apache.directory.api', name: 'api-ldap-model', version: '1.0.0-M15'
// https://mvnrepository.com/artifact/com.opencsv/opencsv
compile group: 'com.opencsv', name: 'opencsv', version: '4.0'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.4.0.jre8'
// https://mvnrepository.com/artifact/net.sourceforge.jtds/jtds
compile group: 'net.sourceforge.jtds', name: 'jtds', version: '1.3.1'
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
// https://mvnrepository.com/artifact/com.rubiconproject.oss/jchronic
compile group: 'com.rubiconproject.oss', name: 'jchronic', version: '0.2.8'
compile group: 'io.github.http-builder-ng', name: 'http-builder-ng-core', version: '1.0.3'
// Use the awesome Spock testing and specification framework
testImplementation 'org.spockframework:spock-core:1.2-groovy-2.5'
}
// Define the main class for the application
mainClassName = 'ssl.test.App'
any help to resolve this error message?
Thanks
SR
You can replace your groovyldap dependency declaration with the following (as already mentioned by #paul-king in the comments):
compile(group: 'org.apache.directory', name: 'groovyldap', version: '0.1-SNAPSHOT') {
exclude group: 'groovy', module: 'groovy'
}
This will at least help you get rid of the dependency resolution error.
I don’t know if your groovyldap dependency will still work with Groovy 2.5.4 but it’s definitely worth a try.
I have a gradle project in IntelliJ IDE in java.
my dependencies is like this:
apply plugin: 'maven-publish'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'com.intellij', name: 'annotations', version: '12.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile files('libs/someJar.jar')
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId group
artifactId 'mylibrary'
version version
from components.java
artifact sourceJar
}
}
}
the problem is when I publish my project in the published jar I didn't find somejar.jar so how can I publish it too.
I want all classes in someJar.jar be next to my main package.
I'm writing java console application using Spring Boot Jpa and MySQL connector. How I can easily exclude all unnecessary libs from my fat jar?
build.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
// mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.2.0'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'ca.cutterslade.analyze'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
mysqlVersion = '6.0.6'
hibernateVersion = '5.2.12.Final'
}
repositories {
mavenCentral()
}
dependencies {
// compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
// compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.12.Final'
// compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
// compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.5.9.RELEASE'
// compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.0.Final'
// compile group: 'org.springframework', name: 'spring-context', version: '4.3.13.RELEASE'
// compile group: 'org.springframework', name: 'spring-beans', version: '4.3.13.RELEASE'
// compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.9.RELEASE'
// compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// compile group: 'org.springframework', name: 'spring-tx', version: '2.5.4'
// compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.9.RELEASE'
// testCompile group: 'org.springframework.boot', name: 'spring-boot-test', version: '1.5.9.RELEASE'
// testCompile group: 'junit', name: 'junit', version: '4.12'
// testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.13.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: mysqlVersion
compile group: 'org.hibernate', name: 'hibernate-core', version: hibernateVersion
compile("org.springframework.boot:spring-boot-starter-data-jpa")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
jar {
baseName 'ReportGenerator'
version '1.0'
}
UPDATE
I have tried to use gradle-dependency-analyze and received the following result:
usedUndeclaredArtifacts:
- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
- org.springframework.boot:spring-boot:1.5.9.RELEASE
- org.springframework:spring-context:4.3.13.RELEASE
- org.springframework:spring-beans:4.3.13.RELEASE
- org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE
- org.slf4j:slf4j-api:1.7.25
- org.springframework:spring-tx:4.3.13.RELEASE
- org.springframework.data:spring-data-jpa:1.11.9.RELEASE
unusedDeclaredArtifacts:
- mysql:mysql-connector-java:6.0.6
- org.hibernate:hibernate-core:5.2.12.Final
- org.springframework.boot:spring-boot-starter-data-jpa:1.5.9.RELEASE
As you see unused libraries are marked all libraries in my gradle at the moment. And required librariesare marked only which are used in the scope of my classes in app but don't get me know what these required libraries depends on also. If I will put only these list of required dependencies in the gradle then I will get different initialization errors since some libraries are missed.
Couple of suggestions.
Use dependency:analyze on your project which will list the unused dependencies, which you can exclude or get rid of.
use the <scope> attribute for each and every dependency in your pom, which can greatly reduce your fat jar size. Provide correct scope parameters, like compile, test .....