I am trying to deploy my Java app into Heroku server with maven heroku plugin. But i am getting such error:
Failed to execute goal com.heroku.sdk:heroku-maven-plugin:3.0.4:deploy (default-cli) on project endlessblow-server: Execution default-cli of goal com.heroku.sdk:heroku-maven-plugin:3.0.4:deploy failed: Failed to create source statuscode:401 responseBody:{"id":"unauthorized","message":"Invalid credentials provided."}
my pom.xml looks like this:
(...)
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<appName>MY_APP</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* pl.jawegiel.Main</web>
</processTypes>
</configuration>
</plugin>
(...)
How to solve that? A few weeks earlier everything was working fine.
Thank you in advance!
From the Maven plugin's doc: https://github.com/heroku/heroku-maven-plugin#heroku-api-key
This plugin uses Heroku's Platform API and thus requires an API key to function. If you have the Heroku CLI installed and logged in with heroku login, the plugin will automatically pick up your API key. Alternatively, you can use the HEROKU_API_KEY environment variable to set your API key
I guess you were previously logged in with Heroku CLI, so running mvn heroku:deploy was working just fine...
I am trying to push my microservice to nexus and at the same time deploy to openshift.
my pom has got this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
This results in the creation of two jar files at the time of build.
my-service-exec.jar
my-service.jar
I took the advice from https://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/maven-plugin/examples/repackage-classifier.html and added the exec classifier in my pom
After deploy and at pod startup I see this error message:
ERROR Neither $JAVA_MAIN_CLASS nor $JAVA_APP_JAR is set and 2 JARs found in /deployments (1 expected)
and the pod is not starting.
Any help in this regard is much appreciated.
By default, the repackage goal will replace the original artifact with the repackaged one. That is a sane behaviour for modules that represent an app, but if your module is used as a dependency of another module, you need to provide a classifier for the repackaged one.
The reason for that is that application classes are packaged in BOOT-INF/classes so that the dependent module cannot load a repackaged jar's classes.
spring docs
I need to set a active profiles to the jars while compile the maven spring boot project
Following are my two Approaches tried to activate the profiles.
First Approach - Not Activating the Profiles
mvn clean package -Dspring-boot.run.profiles=dev help:active-profiles
-s settings.xml
*
Above command not setting the active profiles while executing jars
java -jar package.jar
I have using maven plugin dependencies for activating the first approach
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions> </plugin> </plugins></build>
Second Approach - Working as expected.
mvn clean package -Dspring.profiles.active=dev help:active-profiles -s
settings.xml
java -jar -Dspring.profiles.active=dev package.jar
I'm using multi-module parent pom structure for the project. Any one pls advise to work the first approach?
Maven is a build system. Its responsible for building your artifact.
Maven's profiles are basically a tool that allows to slightly change the build process depending on various factors (operating systems, version of java and so forth).
These are defined in maven's files (pom.xml)
Spring (and Spring boot of course) as opposed to maven is a runtime framework.
Spring profiles is something totally different - they allow to load different beans, resolve different configurations in runtime (read after you call java -jar app.jar) depending on profile definitions.
So don't be confused with the same name, its only an "accidental coincidence"
Now as for your question.
Maven builds the artifact and packages it for that use spring boot maven plugin. If you want to customize this building process - use maven profiles (and as a consequence help:effective-profiles can be sometimes handy).
When the artifact is built - you can run it. For that you can use spring profiles to define runtime in-variants:
- Addresses of databases
- Credentials
- Some subsystems of your product that won't be run locally
and so forth, this list really depends on the application itself.
There is an option to run the spring boot application right from maven and for that you can really use -Dspring.profiles.active=dev but if you don't run it (and you don't in any of suggested approaches, read about mvn spring-boot:run to understand what does it really mean to run a spring boot application during the build), then:
First approach:
mvn clean package -Dspring-boot.run.profiles=dev help:active-profiles
-s settings.xml
-Dspring-boot.run.profiles is irrelevant here - you do nothing with it (again you don't run the project during the build) so it does nothing
java -jar package.jar
Here you can really specify spring profiles with --spring.profiles.active=dev,whatever
The Second approach:
mvn clean package -Dspring.profiles.active=dev help:active-profiles -s
settings.xml
Again, -Dspring.profiles.active=dev is irrelevant, it does nothing.
java -jar -Dspring.profiles.active=dev package.jar
Here you do specify the list of active profiles (just like --spring.profiles.active, from spring boot's standpoint its the same) That's why the application works in runtime as expected
I have a multi module java project. Maven takes almost around 40 secs to build it. I have tried maven with multi threaded builds too by specifying -T and -C args for no of threads and cores to be used. But I haven't seen any significant improvement in wall time of my builds.
I am using maven 3.2.3 and sometimes I need to build my project very frequently.
I know that clean goal take a lot of time but I can not omit it.
Suggestions please....
EDIT:
Note: In my case clean is not taking much time. It finishes in 1 sec. install is taking rest of the time.
Note: First thing is AFAIK, No other in built options available in maven apart from the all answers here.
Running maven build with Multiple threads works for me to speed up the builds.
For example :
mvn clean install -T100
where -T is for specifying how many threads you want based on your
hardware.
Below are the variants from wiki
Maven 3.x has the capability to perform parallel builds. The command
is as follows:
mvn -T 4 clean install Builds with 4 threads
mvn -T 1C clean install 1 thread per cpu core
mvn -T 1.5C clean install 1.5 thread per cpu core
How Execution is evaluated(See Parallel builds in Maven 3)?
Each node in the graph represents a module in a multi-module build, the "levels" simply indicate the distance to the first module in the internal reactor dependency graph. Maven calculates this graph based on declared inter-module dependencies for a multi-module build. Note that the parent maven project is also a dependency, which explains why there is a single node on top of most project graphs. Dependencies outside the reactor do not influence this graph.
Finally if you want to skip test execution you can also use -DskipTests as well.
Caution : Some of your plugins may not be compatible for multithreaded builder, it may work. but it will give below warning message. you may need to see plugin documentation for multithreading support.
[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project *
[WARNING] * contains the following plugin(s) that have goals not marked *
[WARNING] * as #threadSafe to support parallel building. *
[WARNING] * While this /may/ work fine, please look for plugin updates *
[WARNING] * and/or request plugins be made thread-safe. *
[WARNING] * If reporting an issue, report it against the plugin in *
[WARNING] * question, not against maven-core *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked #threadSafe in test-project:
[WARNING] de.dentrassi.maven:rpm:0.9.2
[WARNING] Enable debug to see more precisely which goals are not marked #threadSafe.
[WARNING] *****************************************************************
On my actual project :
mvn clean install [INFO] Total time: 01:05 h
mvn clean install -DskipTests [INFO] Total time: 18:35 min
mvn clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 10:58 min
mvn -T 1C clean install -Dmaven.test.skip -DskipTests [INFO] Total time: 04:00 min
We can also skip the javadoc to be generated as Archmed commented by adding -Dmaven.javadoc.skip=true mvn -T 1C clean install -Dmaven.test.skip -DskipTests -Dmaven.javadoc.skip=true
Don't use * imports, on IntelliJ, choose > Analyze > Run inspection by name > * imports , to find all * imports and correct it.
Remove all unused imports in your project > on Intellij > Analyze > Run inspection by name > unused imports
Remove all unused code (classes, variable, field, parameter, etc..), on Intellij : Analyze > run inspection by name > unused declaration.
Upgrade to last JAVA VERSION
I have found that the task mvn clean, is taking 2 minutes to clean the TARGET folder before building. I did create a new task called quickclean, and I am using it instead of clean, this way mvn -T 1C quickclean install -Dmaven.test.skip -DskipTests . This new task quickclean is only renaming the build folder from TARGET to TARGET-yyyy-MM-dd-HH-mm(what is VERY FAST). So now, every time you make a new mvn quickclean install..., you have a folder with the time of the build. The inconvenient, it's that this may take a lot of space on the hard disk, so you have to clean all these directories sometimes. So for that I have created another task called: trashclean, to put all this folder to trash. I am running this tasks maybe on time per week. or month, depending on my work mvn trashclean.
Here is what you need to add to your pom.xml if you want to use this concept
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd-HH-mm</maven.build.timestamp.format>
<trashdir>trash/target-${maven.build.timestamp}</trashdir>
</properties>
<profile>
<id>quickclean</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>rename_target</id>
<phase>pre-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<move todir="${trashdir}" failonerror="false">
<fileset dir="target/"/>
</move>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>trashclean</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>clean_trash</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete dir="trash/" failonerror="false"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
You can optimize the build by using of some small-2 trick like
If you have written Junit Test and dont want to run test case every time you can use -DskipTests=true
Locally Install Nexus or Repositories
You can adjust memory configurations to optimum for eg: add this line to mvn.bat set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=256m
For more information you can check How to Speed Your Maven build
You can do a hacky way if you have some extra RAM as I do, and you don't need SSD, because it's sensitive for SSD to do a lot of read-writes. Even if you disable +a bit (MacOS - I don't remember if Win have similar issue). But
create RAM drive (number of ways depends on your OS) and mount it to /Users/Username/volatile folder
locate maven-module-builder-X.X.X.jar in MVN_HOME/lib
in JAR modify file org/apache/maven/model/pom-4.0.0.xml by modifying
<build><directory>/Users/Username/volatile/${project.groupId}/${project.artifactId}/${project.version}/target
From now on all project compilations will be done in memory. And it's a difference even in comparison with SSD.
Yes, its hack and some maven plugins can stop working BTW.
If using commandline you can check how many cores your machine has and use all of them, if you also want to skip your tests, you can add -DskipTests
For example, I have 8 core processor:
mvn -T 8C clean install -DskipTests
Apart from parallel run which many of the folks have already mentioned, try these maven options which would speed up build
-XX:+TieredCompilation -XX:TieredStopAtLevel=1
You can try turbo-maven-plugin to help speed up your multi module Maven builds locally (I am one of the plugin authors)?
https://github.com/sparebank1utvikling/turbo-maven-plugin
It works by analyzing what modules actually have code changes, and build only those and the modules dependent on them. More info about how it works here:
https://medium.com/sparebank1-digital/speed-up-your-multi-module-maven-builds-with-turbo-maven-plugin-4be0eb2a2601
Low-Level speed using Ramdisk (Windows)
My additional trick is using a ramdisk
Create a Ramdisk of 2GB (in example D:)
Install IDE, Maven, JDK and the .m2/repository to that Ramdisk (D:/m2/).
Edit the Maven's D:/maven/conf/settings.xml to use that Ramdisked repo (<localRepository>D:/m2</localRepository>)
Put the project into the ramdisk.
Run the project having its temp-folder in the Ramdisk.
On my machine I turned
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.954 s (Wall Clock)
[INFO] Finished at: 2021-02-17T13:07:51+01:00
[INFO] Final Memory: 55M/642M
[INFO] ------------------------------------------------------------------------
Into
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.805 s (Wall Clock)
[INFO] Finished at: 2021-11-11T10:48:14Z
[INFO] ------------------------------------------------------------------------
Both results are high-end (-DskipTests -T 12)
Warning: Do not forget to persist the ramdisk before shutdown or your work is lost.
Look at this beast:
If you are using spring boot with maven and you feel like dependencies are coming slow to your system, try following setting in pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath />
</parent>
I experienced that version 2.7.0 downloads the dependencies faster than other versions.
Im having a strange problem when im trying to let the wagon plugin upload files during the site-deploy lifecycle when i'm invoking the release:perform goal.
It seems wagon uploads the files correctly when im invoking mvn site-deploy but it just responds with
Nothing to upload
when calling mvn release:perform which is supposed to invoke the phases site site-deploy as stated in the documentation.
this is the plugin config for wagon.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>upload-jars</id>
<phase>deploy site-deploy</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>target/checkout/target</fromDir>
<includes>*.jar</includes>
<url>scpexe://nohost.com</url>
<toDir>/var/www/projects/test</toDir>
<serverId>server - projects</serverId>
</configuration>
</execution>
</executions>
</plugin>
maven tells me the right goals were started:
[INFO] Executing goals 'deploy site-deploy'...
[INFO] [INFO] Scanning for projects...
but wagon doesn't upload anything:
[INFO] [INFO] --- wagon-maven-plugin:1.0-beta-3:upload (default) # exp4j ---
[INFO] [INFO] Nothing to upload.
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESS
Does anyone spot my problem that causes maven to work as expected when invoking site-deploy but failing when doing a release:perform ?
This plugin does not do what you think it does. Trust me, I've been there.
The underlying wagon protocol is only intended for talking to Maven Repositories, not arbitrary directories. If the stuff you are pushing doesn't have files and directories in the pattern of a repo, the plugin will decide that there's nothing for it to do.
I spent hours and hours and hours on this, and read the code, and reached the conclusion that this plugin is not intended to be useful for pushing arbitrary files to arbitrary places, and in fact does not work for that purpose.
I had the same issue until I've found at that the "includes" tag must contains "/*" to recursively include files and subdirectories.
See comments of that blog post
<includes>*/**</includes>