Heroku deploy build failure for Spring Boot REST API - java

I have a Spring Boot REST API locally.
It is successfully generating the .war file locally when I run mvn clean package.
Now I want to deploy it to Heroku.
These are the steps I've done.
Uploded the code to a github respository. Let's say \myrestapi.
Opened a terminal to run Heroku CLI commands
Logged in heroku
heroku login
Ran command to create the app on heroku
heroku create myrestapi
This command didn't work. Got the message saying the name "myrestapi" already existed.
So I changed the name to something else. Let's say "cl-myrestapi":
heroku create cl-myrestapi
It ran successfully.
Ran command to create the free postgreSQL database on heroku:
heroku addons:create heroku-postgresql:hobby-dev
Git push
git push heroku main
This starts downloads successfully.
But then generates the following error:
remote: [INFO] BUILD FAILURE
remote: [INFO] ------------------------------------------------------------------------
remote: [INFO] Total time: 14.653 s
remote: [INFO] Finished at: 2021-02-19T18:43:12Z
remote: [INFO] ------------------------------------------------------------------------
remote: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-
compile) on project myrestapi: Fatal error compiling: invalid target release: 11 -> [Help 1]
remote: [ERROR]
remote: [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote: [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote: [ERROR]
remote: [ERROR] For more information about the errors and possible solutions, please read the following artic
les:
remote: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
remote:
remote: ! ERROR: Failed to build app with Maven
remote: We're sorry this build is failing! If you can't find the issue in application code,
remote: please submit a ticket so we can help: https://help.heroku.com/
remote:
remote: ! Push rejected, failed to compile Java app.
remote:
remote: ! Push failed
remote: !
remote: ! ## Warning - The same version of this code has already been built: e11a85238783f54ee30765ba4f8a55354930be
09
remote: !
remote: ! We have detected that you have triggered a build from source code with version e11a85238783f54ee30765ba4f
8a55354930be09
remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote: !
remote: ! If you are developing on a branch and deploying via git you must run:
remote: !
remote: ! git push heroku <branchname>:main
remote: !
remote: ! This article goes into details on the behavior:
remote: ! https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote:
remote: ! Push rejected to cl-myrestapi.
remote:
To https://git.heroku.com/cl-myrestapi.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cl-myrestapi.git'
Why am I getting this error since it is building successfully locally?
There are only two differences I can see:
The need to have a different project name on heroku (see step 4 above)
Application.properties is different.
This is my original application.properties (that runs locally).
spring.datasource.url=jdbc:postgresql://localhost:5432/myrestapi
spring.datasource.username=xxx
spring.datasource.password=yyy
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
This is the updated application.properties (being uploaded to heroku)
spring.datasource.url=${JDBC_DATASOURCE_URL}
spring.jpa.hibernate.ddl-auto=update
UPATE:
Noted that when the git push heroku main command is executed, at the begining it says "Installing jdk 1.8", while I'm using version 11.
So that seems to be the issue.
To solve that I tried to add a System.properties file at the root with the following line:
java.runtime.version=11
But didn't solve.

First Don't forget to add this in pom.xml
<properties>
<java.version>11</java.version>
</properties>
Second, check project SDK and project language level (in project structure) both of them should be 11.
Check Java compiler in settings and make sure that project-byte-code-version
and target-byte-code-version have set 11.
Also for last chance if Heroku can't deploy, try this at bottom of your pom.xml file.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Related

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project binance-futures-connector-java

the other day I tried to start using API from Binance. I stumbled across this library I found on Binance Git Hub (https://github.com/binance/binance-futures-connector-java). I never worked with Maven, so I was and still am quite a bit lost.
I followed the installation so firstly I downloaded ZIP. Unzipped it, went to the folder where was pom.xml file and from that path run command in cmd mvn install. I got this error:
Tests in error:
testNewOrder(unit.cm_futures.account.TestCMNewOrder)
testNewOrder(unit.um_futures.account.TestUMNewOrder)
Tests run: 302, Failures: 3, Errors: 2, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.241 s
[INFO] Finished at: 2023-01-12T12:55:38+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project binance-futures-connector-java: There are test failures.
My pom.xml file is copy-paste what I downloaded
I see that error comes from tests in testNewOrder(unit.cm_futures.account.TestCMNewOrder) and testNewOrder(unit.um_futures.account.TestUMNewOrder), but I have no idea what to do.
I set the API and KEY in PrivateConfig.
I tried the following:
-Adding this piece of code to pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
-using command mvn clean install -U
Still getting the same error.
If I somehow fix this error later when I create a new project in IntelliJ IDEA. I choose Maven and in pom.xml just add(from installation instructions)
> <dependency>
> <groupId>io.github.binance</groupId>
> <artifactId>binance-futures-connector-java</artifactId>
> <version>LATEST_VERSION(1.0.0)</version>
> </dependency>
correct?
Thanks in advance!

Error When Building App with Maven Using Heroku

I'm trying to deploy my Discord bot using Heroku but everytime I deploy it, it gives me an error. The code works on local using IntelliJ Idea. Can anyone help me correct this error please?
Build log:
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 21 source files to /tmp/build_8fdb6208/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.237 s
[INFO] Finished at: 2021-03-21T23:52:06Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project CalciteDiscordBot: Fatal error compiling: invalid target release: 15 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
! ERROR: Failed to build app with Maven
We're sorry this build is failing! If you can't find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed
Here's my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>CalciteDiscordBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.source>15</maven.compiler.source>
</properties>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_168</version>
</dependency>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</project>
Someone just helped me with this issue yesterday your Maven POM specifies that you want Java 15, but the Java version installed cannot handle compilation for 15. So, add a system.properties file to your application root with the following contents and build again:
java.runtime.version=15
You application requires Java 15 (<maven.compiler.source>15</maven.compiler.source>) so you need tell Heroku you want that specific Java version (instead of the default one)
In the root folder place a file system.properties:
java.runtime.version=15

Not able to upload artifacts to Nexus from the same machine using mvn clean deploy, works fine from my local Windows 10 machine

Java 11
I have a very basic Spring Boot application that I would like to build and deploy the artifacts on a Nexus sever.
mvn clean deploy (from my local Win 10 machine - WORKS !!!)
mvn clean deploy (from Nexus machine - FAILS ????)
mvn clean deploy (from Jenkins - FAILS ????)
When I run mvn clean deploy command from my local Win 10 machine all the artifacts get deployed successfully on remote Nexus server and I can even see and browse them.
But when I clone the project and run mvn clean deploy on the very same machine where both Nexus and Jenkins (Ubuntu box) are installed it gives me Not authorized error.
I have already copied over BOTH settings.xml and settings-security.xml from my local Windows machine to Ubuntu (~/.m2) where Nexus is installed.
I have disabled the firewalls as well just to be sure that no ports are blocked.
I am confused how the artifacts are getting copied over from a remote machine but not from the same machine.
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>my-maven-snapshots</id>
<url>http://my-nexus-server/nexus/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>my-maven-releases</id>
<url>http://my-nexus-server/nexus/repository/maven-releases/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:https://johndoe#bitbucket.org/johndoe/todo.git</connection>
<url>https://johndoe#bitbucket.org/johndoe/todo</url>
<developerConnection>scm:git:https://johndoe#bitbucket.org/johndoe/todo.git</developerConnection>
<tag>HEAD</tag>
</scm>
Error (Nexus is installed on this machine):
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # todo ---
[INFO] Installing /home/admin/cloned-apps/todo/pom.xml to /home/admin/.m2/repository/com/example/todo/0.0.2-SNAPSHOT/todo-0.0.2-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # todo ---
Downloading from my-maven-snapshots: http://my-nexus-server/nexus/repository/maven-snapshots/com/example/todo/0.0.2-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata com.example:todo:0.0.2-SNAPSHOT/maven-metadata.xml from/to my-maven-snapshots (http://my-nexus-server/nexus/repository/maven-snapshots/): Not authorized , ReasonPhrase:Unauthorized.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for todo 0.0.2-SNAPSHOT:
[INFO]
[INFO] todo ............................................... FAILURE [ 4.622 s]
[INFO] todo-webapp ........................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.973 s
[INFO] Finished at: 2020-04-16T02:39:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project todo: Failed to retrieve remote metadata com.example:todo:0.0.2-SNAPSHOT /maven-metadata.xml: Could not transfer metadata com.example:todo:0.0.2-SNAPSHOT/maven-metadata.xml from/to my-maven-snapshots (http://my-nexus-server/nexus/repository/maven-snapshots/ ): Not authorized , ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
mvn clean deploy (from Nexus machine - FAILS ????)
Are you sure you're running mvn clean deploy from the same user under whose $HOME/.m2 directory you've copied the settings.xml and settings-security.xml files?
Also, did you try adding the password directly to settings.xml to rule out issues (if any) with settings-security.xml?
P.S: Avoid running mvn commands with sudo privilege.

Heroku unable to detect java 11

I am trying to deploy a java jar to heroku with heroku maven plugin.
I am using java 11 so I have added system.properties in the root folder(where pom.xml is present) and set java.runtime.version=11. However it doesn't seem to be working !
My plugin :
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<includeTarget>false</includeTarget>
<includes>
<include>${project.build.directory}/${project.build.finalName}.jar</include>
</includes>
<processTypes>
<web>java $JAVA_OPTS -jar ${project.build.directory}/${project.build.finalName}.jar</web>
</processTypes>
</configuration>
</plugin>
When I do git push heroku master it starts build process using jdk 8.
remote: Building source:
remote:
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote: $ mvn -DskipTests clean dependency:list install
Eventually build fails with error :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ImpactHub_bot: Fatal error compiling: invalid flag: --release ->
How do I set jdk verison to 11 ? I have also tried adding ${java.version} to configuration but it didn't help
That's exactly how you are specifying the Java version, see: https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
You can specify a Java version by adding a file called
system.properties to your application.
Set a property java.runtime.version in the file:
java.runtime.version=11
I used it in my project as well and it is working.
Make sure your system.properties is saved as All Files. Furthermore it should be at the root folder of your git repo.
It might have a .txt ending. If that fails open a Support Ticket with Heroku.

maven-release-plugin [ERROR] fatal: pathspec '' did not match any files

I'm trying to do a release of my OSS library, but I keep running in to a strange issue with the maven-release-plugin. This used to work fine. I've probably updated either Maven or Git but I can't seem to find the right combination to get things working again for the release.
Has anyone run into this issue, and does anyone know of a solution? I'm using the Maven Shade Plugin (which is what is creating the dependency-reduced-pom.xml files in the build.)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 09:27 min
[INFO] Finished at: 2015-11-04T08:23:07-05:00
[INFO] Final Memory: 111M/1039M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.1:prepare (default-cli) on project rewrite-parent: Unable to commit files
[ERROR] Provider message:
[ERROR] The git-add command failed.
[ERROR] Command output:
[ERROR] fatal: pathspec 'config-prettyfaces/dependency-reduced-pom.xml' did not match any files
[ERROR] -> [Help 1]
The dependency-reduced-pom.xml, as I understand it, is a temporary file used while merging dependencies into an uber-jar, and should not be committed, so I'm confused why maven is trying to add this file at all.
Thanks for any help.
I figured it out, at least a workaround:
Using 'checkModificationExcludes" configuration option of the maven-release-plugin to exclude the dependency-reduced-pom.xml seems to work around the issue, though I'm not sure this is exactly what the property was intended for (the documentation is unclear):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>dependency-reduced-pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>

Categories