I'm trying to set basic workspace for Spring boot and gradle.
Everything works perfectly in local and in travis, but in heroku build fails. I don't think the problem is in the actual code, but in the configuration.
Here is my project in github.
build.gradle
plugins {
id 'java'
id 'maven'
id 'jacoco'
id 'org.springframework.boot' version '1.5.3.RELEASE'
}
group = 'org.karlin'
version = '0.1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
bootRepackage {
mainClass = 'gramise.Gramise'
}
repositories {
maven {
url("https://plugins.gradle.org/m2/")
}
}
dependencies {
compile("com.google.code.gson:gson")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.postgresql:postgresql")
compile("org.apache.commons:commons-dbcp2")
compile("com.h2database:h2")
testCompile(group: 'org.springframework.boot', name: 'spring-boot-
starter-test', version:'1.5.3.RELEASE') {
exclude(module: 'commons-logging')
}
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.2.0'
}
task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean
There is heroku build log
-----> Gradle app detected
-----> Installing OpenJDK 1.8... done
-----> Installing Gradle Wrapper...
WARNING: Your application does not have it's own gradlew file.
-----> Building Gradle app...
-----> executing ./gradlew build
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-tools/1.5.3.RELEASE/spring-boot-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.pom
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.pom
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/1.5.3.RELEASE/spring-boot-gradle-plugin-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/1.5.3.RELEASE/spring-boot-loader-tools-1.5.3.RELEASE.jar
Download https://plugins.gradle.org/m2/io/spring/gradle/dependency-management-plugin/1.0.2.RELEASE/dependency-management-plugin-1.0.2.RELEASE.jar
Download https://plugins.gradle.org/m2/org/springframework/spring-core/4.3.8.RELEASE/spring-core-4.3.8.RELEASE.jar
FAILURE: Build failed with an exception.
* What went wrong:
org/gradle/api/plugins/JavaPlugin
> org.gradle.api.plugins.JavaPlugin
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
You need to check gradlew into Git.
WARNING: Your application does not have it's own gradlew file.
Because you are not doing this, Heroku is using a very old version of Gradle.
If someone else is encountering this problem, this fixed it
I added buildscript in build.gradle
buildscript {
ext {
springBootVersion = '1.5.3.RELEASE'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
Now everything is working, thanks for help.
Related
I want to create an executable Jar for Spring Boot using gradle in an offline environment.
There is an error.
Please tell me the solution.
■cmd
C: / ~ / ~ / demo gradlew bootJar --offline --stacktrace
FAILURE: Build failed with an excetion.
What went wrong:
Task 'bootJar' not found in root project 'demo'.
Exception is:
org.gradle.execution. TaskSelectionException: Task 'bootJar' not found in root project 'demo'.
......
■build.gradle
plugins {
// id 'org.springframework.boot' version '2.4.2'
// id 'io.spring.dependency-management' version '1.0.11.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'
}
test {
useJUnitPlatform()
}
■gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
■version
SpringBoot:2.4.2
gradle:6.6.1
The bootJar task comes from the Spring Boot Gradle plugin (org.springframework.boot). You've removed the plugin from the project therefore the bootJar task never gets created.
Gradle is smart enough to cache various parts of the build including dependencies and plugins. However, since you are getting that error, the Spring Boot plugin is not cached therefore you must go online temporarily in order for the plugin to be downloaded and cached.
If you're not able to temporarily go online, then for the bootJar task specifically, you must reimplement yourself in your project: https://github.com/spring-projects/spring-boot/blob/2.4.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
I've created a demo Gradle project called test-jdbc-demo from Spring using some dependencies and change nothing, just unziped and imported on Intellij using Open -> build.gradle file and tried too using Import from default Intellij window. When imported the project is not build and a error about gradle dependencies occurs. I'm using Intellij 2019.3, JDK 1.8 on Ubuntu.
Error
FAILURE: Build failed with an exception.
* Where:
Build file '/home/augusto.cadini/projects/Spring Applications/test-jdbc-demo/build.gradle' line: 2
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.2.4.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
CONFIGURE FAILED in 208ms
build.gradle
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.jdbc'
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-jdbc'
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()
}
This drove me crazy. I was getting the same errors (this is from a clean project generated from Spring Initializr). Turned out it was an issue with the Gradle version. When I ran a build from the command line, I got the following error message
Once I updated gradle it build with no issues.
I'm newbie to Hyperledger Fabric. When i instantiate the chaincode written in java after installed on peers from the cli container, there is something wrong:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.github.everit-org.json-schema:org.everit.json.schema:1.11.1.
Searched in the following locations:
file:/root/.m2/repository/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.pom
file:/root/.m2/repository/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.jar
https://repo.maven.apache.org/maven2/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.pom
https://repo.maven.apache.org/maven2/com/github/everit-org/json-schema/org.everit.json.schema/1.11.1/org.everit.json.schema-1.11.1.jar
Required by:
project : > org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.2
I thought it might be the maven repository's issue, but when i use gradle in my host's terminal, it runs ok like:
fabric#ubuntu:~/fabric1.4/fabric-samples/chaincode/master-liuqi/java$ sudo /opt/gradle/bin/gradle -b build.gradle build
Task :compileJava
Note: /home/fabric/fabric1.4/fabric-samples/chaincode/master-liuqi/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed
below is my build.gradle, It is the same as the hyperleger's example chaincode.
plugins {
id 'com.github.johnrengelman.shadow' version '2.0.3'
id 'java'
}
group 'org.hyperledger.fabric-chaincode-java'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile group: 'org.hyperledger.fabric-chaincode-java', name: 'fabric-chaincode-shim', version: '1.+'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
shadowJar {
baseName = 'chaincode'
version = null
classifier = null
manifest {
attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
}
}
Is there any way to solve this problem? and what is the difference in running gradle build within host and container?
Actually, you should use
repositories {
mavenLocal()
mavenCentral()
maven {
maven { url 'https://jitpack.io' }
}
}
repo instead of repo from the other answer, since this repo is recommended in official json-schema documentation.
Quote:
Add the JitPack repository and the dependency to your pom.xml as
follows:
(see: https://github.com/everit-org/json-schema)
I searched the maven repository(https://mvnrepository.com/artifact/org.hyperledger.fabric-chaincode-java/fabric-chaincode-shim/1.4.2), found that this dependency is not in maven central repository. After adding repository in build.gradle as follows:
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://repository.mulesoft.org/nexus/content/repositories/public/"
}
}
it works well now. since i am not familar with gradle, i still wonder why i can build successfully in host while failed in cli container ?
When compiling and building my android app, an error as shown below keeps occurring. I have been using this stack overflow answer to solve the error and exclude the duplicate files.
Here is the error I get when I try to build my project.
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt
File1: /Users/tomfinet/.gradle/caches/modules-2/files-2.1/com.google.appengine/appengine-api-1.0-sdk/1.9.28/e92c18272b555027d9ec666e7a89162f10638314/appengine-api-1.0-sdk-1.9.28.jar
File2: /Users/tomfinet/.gradle/caches/modules-2/files-2.1/com.google.appengine/appengine-endpoints/1.9.28/bf2e8a74bd28e388b3487fc78a0c7adfa592fd5d/appengine-endpoints-1.9.28.jar
When I run the terminal command ./gradlew dependencies as instructed in the stack overflow answer, I am supposed to see the entire dependency tree for my project.
However all I see is this:
Downloading https://services.gradle.org/distributions/gradle-2.10-all.zip
.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Unzipping /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10-all.zip to /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst
Set executable permissions for: /Users/tomfinet/.gradle/wrapper/dists/gradle-2.10-all/a4w5fzrkeut1ox71xslb49gst/gradle-2.10/bin/gradle
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.
Incremental java compilation is an incubating feature.
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
BUILD SUCCESSFUL
Total time: 53.171 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Here is my gradle file for the backend:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.28'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.28'
compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.0.3'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
So how do I resolve this conflict between the dependencies? I am pretty sure I have to exclude the conflicting files. But how do I find the files that are causing this?
I am new to gradle please pardon my ignorance. Have a basic gradle project.
I get the following error when I run ./gradlew tasks
FAILURE: Build failed with an exception.
* Where:
Build file '<path>/build.gradle' line: 17
* What went wrong:
> No signature of method: build_204u1riu5haork78eb2ib9dc1t$_run_closure2.id() is applicable for argument types: (java.lang.String) values: [com.jfrog.artifactory]
Possible solutions: is(java.lang.Object), is(java.lang.Object), find(), find(), find(groovy.lang.Closure), find(groovy.lang.Closure)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Following is my build.gradle
buildscript {
repositories {
maven {
url '<URL>'
credentials {
username = "<USERNAME>"
password = "<PASSWORD>"
}
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
plugins {
id "com.jfrog.artifactory" version "3.0.1" //<=== LINE 17
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'application'
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = "<URL>"
publish {
repository {
repoKey = 'libs-snapshot-local'
username = "<USERNAME>"
password = "<PASSWORD>"
maven = true
}
defaults {
publications('mavenJava')
}
}
resolve {
repository {
repoKey = 'libs-all'
username = "<USERNAME>"
password = "<PASSWORD>"
maven = true
}
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.slf4j:slf4j-simple:1.7.7'
compile 'com.amazonaws:aws-java-sdk:1.9.38'
testCompile 'junit:junit:4.11'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
I am sure it is a very basic issue which is why when I googled around, did not find any solutions. Would be great if someone could point me in the right direction or share a link to any previous related issues.
This can happen if you are building using Gradle 1.x. The Gradle plugins DSL was introduced in Gradle 2.1 and is not supported by older Gradle version.
You have gradle wrapper configured to use Gradle 2.2, but you need to make sure you are using the gradlew script instead of gradle
Another possibility is if you have any module in your project which has lower version gradle tools
e.g my app module had below build tools as dependency in buildscript
classpath 'com.android.tools.build:gradle:2.3.2'
but I had another module with below build tools as dependency in buildscriptclasspath 'com.android.tools.build:gradle:2.2.0'
In this situation I got below error
No signature of method: org.jfrog.gradle.plugin.artifactory.extractor.listener.ProjectsEvaluatedBuildListener$_projectsEvaluated_closure1.doCall() is applicable for argument types: (org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask_Decorated) values: [task ':uid:artifactoryPublish']
Then after changing
classpath 'com.android.tools.build:gradle:2.2.0' to classpath 'com.android.tools.build:gradle:2.3.2' everything worked well.