how to hide the extra details? - java

I'm new to java. I was wondering that how can I hide the extra details whenever I run a class or a whole project. I only want to see "hello world" not the rest of the detail, if it's possible.
cd /home/hamza/NetBeansProjects/testing; JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 /home/hamza/netbeans/java/maven/bin/mvn "-Dexec.args=-classpath %classpath application.testing.hello" -Dexec.executable=/usr/lib/jvm/java-11-openjdk-amd64/bin/java -Dexec.classpathScope=runtime process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
Scanning for projects...
------------------------------------------------------------------------
Building testing 1.0-SNAPSHOT
------------------------------------------------------------------------
--- maven-resources-plugin:2.6:resources (default-resources) # testing ---
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory /home/hamza/NetBeansProjects/testing/src/main/resources
--- maven-compiler-plugin:3.1:compile (default-compile) # testing ---
Nothing to compile - all classes are up to date
--- exec-maven-plugin:1.5.0:exec (default-cli) # testing ---
hello world
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1.342 s
Finished at: 2020-02-29T21:54:11+05:00
Final Memory: 9M/37M
------------------------------------------------------------------------

Run the mvn command using --quiet or -q parameter:
mvn --quiet ...
or
mvn -q ... ...
If you want to suppress the display of transfer progress when downloading or uploading, use --no-transfer-progress or -ntp:
mvn --no-transfer-progress ....
or
mvn -ntp ... ....
Check here for reference.
Click the Maven Settings button shown in the screenshot below:
Type -q in the box shown in the screenshot below:
Press OK button and then run your class.

Related

maven release plugin fails second time on gitlab

I setup a pipeline on gitlab but I get a weird error "You don't have a SNAPSHOT project in the reactor projects list"
I'm just trying to deploy a java spring boot.
Below the pom.xml (only what's relevant)
<name>Project Phoenix - Base</name>
<groupId>com.gfs</groupId>
<artifactId>phoenix</artifactId>
<version>1.12-SNAPSHOT</version>
<packaging>pom</packaging>
...
<scm>
<developerConnection>scm:git:${project.scm.url}</developerConnection>
<url>git#gitlab.com:"myuser"/phoenix.git</url>
<tag>HEAD</tag>
</scm>
....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin}</version>
<configuration>
<scmDevelopmentCommitComment>#{prefix} prepare for next development iteration [skip ci]</scmDevelopmentCommitComment>
</configuration>
</plugin>
My gitlab-ci.yml looks like this:
workflow:
rules:
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH == 'master'
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
MAVEN_CLI_OPTS: "-s settings.xml --batch-mode --errors --fail-at-end --show-version"
MAVEN_IMAGE: maven:3.8.5-openjdk-17-slim
services:
- docker:dind
stages:
- build
- release
cache:
paths:
- .m2/repository/
- target/
build-job:
image: $MAVEN_IMAGE
stage: build
script:
- echo "Building $MODULE"
- mvn clean package -B $MAVEN_CLI_OPTS
release-job:
image: $MAVEN_IMAGE
stage: release
tags:
- local-runner
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- apt-get update -qq
- apt-get install -qq git
- git config --global user.email "hidden"
- git config --global user.name "hidden"
- git checkout -B "$CI_COMMIT_REF_NAME"
script:
- echo "Creating the release"
- mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
only:
- master
After I push, gitlab starts a pipeline on the commit which is successful and it deploys in the gitlab package registry the snapshot and the release.
However, there are other 2 pipeline starting
[maven-release-plugin] which it seems it does the same things but it fails:
First it says:
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Then it says: You don't have a SNAPSHOT project in the reactor projects list
$ git checkout -B "$CI_COMMIT_REF_NAME"
Switched to and reset branch 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
$ echo "Creating the release"
Creating the release
$ mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/share/maven
Java version: 17.0.2, vendor: Oracle Corporation, runtime: /usr/local/openjdk-17
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.104-linuxkit", arch: "aarch64", family: "unix"
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.gfs:phoenix >---------------------------
[INFO] Building Project Phoenix - Base 1.11
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # phoenix ---
[INFO] Deleting /builds/gfalco77/phoenix/target
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) # phoenix ---
[INFO] argLine set to -javaagent:/builds/gfalco77/phoenix/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/builds/gfalco77/phoenix/target/jacoco.exec
[INFO]
[INFO] --- spring-boot-maven-plugin:2.6.7:repackage (repackage) # phoenix ---
[INFO]
[INFO] --- maven-failsafe-plugin:3.0.0-M6:integration-test (default) # phoenix ---
[INFO] No tests to run.
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) # phoenix ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- maven-failsafe-plugin:3.0.0-M6:verify (default) # phoenix ---
[INFO] Failsafe report directory: /builds/gfalco77/phoenix/target/failsafe-reports
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) # phoenix ---
[INFO] Installing /builds/gfalco77/phoenix/pom.xml to /builds/gfalco77/phoenix/.m2/repository/com/gfs/phoenix/1.11/phoenix-1.11.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # phoenix ---
[INFO] Uploading to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/1.11/phoenix-1.11.pom
[INFO] Uploaded to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/1.11/phoenix-1.11.pom (6.5 kB at 2.2 kB/s)
[INFO] Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml
[INFO] Downloaded from gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml (361 B at 334 B/s)
[INFO] Uploading to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml
[INFO] Uploaded to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml (361 B at 111 B/s)
[INFO]
[INFO] --------------------------< com.gfs:phoenix >---------------------------
[INFO] Building Project Phoenix - Base 1.11
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-release-plugin:3.0.0-M5:prepare (default-cli) # phoenix ---
[INFO] phase verify-release-configuration
[INFO] starting prepare goal, composed of 17 phases: check-poms, scm-check-modifications, check-dependency-snapshots, create-backup-poms, map-release-versions, input-variables, map-development-versions, rewrite-poms-for-release, generate-release-poms, run-preparation-goals, scm-commit-release, scm-tag, rewrite-poms-for-development, remove-release-poms, run-completion-goals, scm-commit-development, end-release
[INFO] [prepare] 1/17 check-poms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.246 s
[INFO] Finished at: 2022-07-13T16:57:18Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M5:prepare (default-cli) on project phoenix: You don't have a SNAPSHOT project in the reactor projects list. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M5:prepare (default-cli) on project phoenix: You don't have a SNAPSHOT project in the reactor projects list.
The third and last pipeline is
[maven-release-plugin] prepare for next development iteration [skip ci] which is Skipped..
Does anybody know what it should happen, why does it complain on the snapshot?
Thanks
Basically, if not that error you would run in infinite loop :) The release:prepare performs the following steps:
Check that there are no uncommitted changes in the sources
Check that there are no SNAPSHOT dependencies
Change the version in the POMs from x-SNAPSHOT to a new version (you will be prompted for the versions to use)
Transform the SCM information in the POM to include the final destination of the tag
Run the project tests (preparation goals) against the modified POMs to confirm everything is in working order
Commit the modified POMs
Tag the code in the SCM with a version name (this will be prompted for)
Bump the version in the POMs to a new value y-SNAPSHOT (these values will also be prompted for)
Eventually run completion goal(s) against the project (since 2.2)
Commit the modified POMs
So, upon completion of your CI pipeline you are getting two new commits into master branch:
[maven-release-plugin] prepare for next development iteration
[maven-release-plugin] prepare release XXX
which in turn triggers your CI pipeline again, you just need to disable pipeline triggering for specific CI_COMMIT_MESSAGE (or setup scmReleaseCommitComment, which actually looks not so good as well as scmDevelopmentCommitComment)
UPD.
I have revised your release pipeline I can definitely say everything you are doing is wrong. The main problem is you are trying to implement release pipeline relying on suggestions from internet (e.g. what you have provided looks very similar to https://forum.gitlab.com/t/getting-mvn-release-to-work-with-gitlab-ci/4904) instead of basing on best practices and common sense...
what is the purpose of the following code snippet?
stages:
- build
- release
...
build-job:
image: $MAVEN_IMAGE
stage: build
script:
- echo "Building $MODULE"
- mvn clean package -B $MAVEN_CLI_OPTS
...
release-job:
stage: release
...
script:
- echo "Creating the release"
- mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
mvn package performs compile, test and package
mvn deploy performs compile, test, package, verify and deploy
release:prepare by default performs mvn clean verify
so, in your release pipeline you perform compile and test three times, and verify two times, which actually sounds good for your SaaS provider: more resources you consume - more money you spend.
following code snippet:
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- apt-get update -qq
- apt-get install -qq git
- git config --global user.email "hidden"
- git config --global user.name "hidden"
actually assumes you supposed to create your own docker images which contains jdk, maven, ssh, git and other toolchain stuff.
following code snippet:
before_script:
...
- git checkout -B "$CI_COMMIT_REF_NAME"
reveals that Gitlab is neither CI nor CD, the question is: what commit your release is based on? The answer is: on something after my commit :)

How run tests on Heroku with Maven

How do I run tests on Java Maven app on Heroku. I am using autodeploy linked to a branch on Github.
The default Maven command run on Heroku is:
mvn -DskipTests clean dependency:list install
To remove the skipTests, I set the MAVEN_CUSTOM_OPTS as described on https://github.com/heroku/heroku-buildpack-java#customize-maven.
However this does not result on the tests to be run. Looking at the build log I can see:
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (java-test-compile) # myapp ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M1:test (default-test) # myapp ---
[INFO] No tests to run.
Compared to running Maven locally, I can see:
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (java-test-compile) # myapp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to ...
So it would seem there is an issue with Heroku ignoring my test resources and code.
the Heroku deployment only builds and deploys your application into a Dyno.
If you need a CI environment there's Heroku CI (not free) or you can use the Azure GitHub pipelines (free for GitHub projects)
Beppe

Why my maven package triggered by Jenkins failed but can be success if I manually execute it?

I have a jenkins job which tend to build my java application using maven, but it always gets failure during the compile phase.
[[1;34mINFO[m] Changes detected - recompiling the module!
[[1;34mINFO[m] Compiling 550 source files to /var/lib/jenkins/workspace/test/target/classes
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1;31mBUILD FAILURE[m
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] Total time: 9.575 s
[[1;34mINFO[m] Finished at: 2017-12-02T07:47:47+08:00
[[1;34mINFO[m] Final Memory: 24M/346M
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;33mWARNING[m] The requested profile "nexus" could not be activated because it does not exist.
[[1;31mERROR[m] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.1:compile[m [1m(default-compile)[m on project [36mtest[m: [1;31mCompilation failure[m -> [1m[Help 1][m
[[1;31mERROR[m]
I find and copied the below command in the Jenkins job's console output(on the webpage).
/opt/apache-maven-3.5.0/bin/mvn -f pom.xml -s /var/lib/jenkins/test-maven-setting/setting.xml -gs /var/lib/jenkins/test-maven-setting/setting.xml -Dmaven.repo.local=/var/lib/jenkins/workspace/test/.repository clean package
Then I switched to the jenkins user in the Linux console and go to the job's workspace directory and tried to manually execute the above commands I copied.
but it success!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.994 s
[INFO] Finished at: 2017-12-02T07:50:17+08:00
[INFO] Final Memory: 35M/298M
so it's very strange, same commands, same user, same directory, but it can success when I execute it manually while fail when Jenkins build the job. Does anyone know what's the problem that Jenkins job failed?
here I retested the maven plugin and pasted some screenshots.
You as using "use default maven settings" option in invoke-maven-targets.
select option for "settings file in filesystem" for both default and global

Maven release plugin. branch release fails (+ missing first letter of branch name)

Added
If my branch is default, maven:prepare completed successfully.
/Added
I have maven project in Idea. Using mercurial.
I have created branch "MAVEN_RELEASE" to try to release it with maven-release-plugin. And got the following error. Please follow the hg push line. Is cause of the problem is AVEN_RELEASE (no first letter)?
[INFO] [INFO] BUILD SUCCESS
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 02:16 min
[INFO] [INFO] Finished at: 2016-05-12T17:53:53+06:00
[INFO] [INFO] Final Memory: 63M/216M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Checking in modified POMs...
[INFO] EXECUTING: cmd.exe /X /C "hg branch"
[INFO] EXECUTING: cmd.exe /X /C "hg outgoing"
[WARNING] A different branch than AVEN_RELEASE was found in outgoing changes, branch name was MAVEN_RELEASE. Only local branch named AVEN_RELEASE will be pushed.
[INFO] EXECUTING: cmd.exe /X /C "hg commit --message "[maven-release-plugin] prepare release sea-bni-1.0.5" C:\EA\IdeaProjects\sea-eclipse\pom.xml C:\EA\IdeaProjects\sea-eclipse\jnlp-apps\pom.xml C:\EA\IdeaProjects\sea-eclipse\jnlp-apps\arm-data-entry\pom.xml C:\EA\IdeaProjects\sea-eclipse\jnlp-apps\sea-print\pom.xml C:\EA\IdeaProjects\sea-eclipse\sea-web\pom.xml C:\EA\IdeaProjects\sea-eclipse\the-ear\pom.xml"
[INFO] EXECUTING: cmd.exe /X /C "hg push -rAVEN_RELEASE http://oksapp.bingo.ru/hg/sea-eclipse"
[ERROR]
EXECUTION FAILED
Execution of cmd : push failed with exit code: 255.
Working directory was:
C:\EA\IdeaProjects\sea-eclipse
Your Hg installation seems to be valid and complete.
Hg version: 3.5.2 (OK)
Second question, please:
2) Should I do deploy action before doing maven release prepeare, perform?
Should be resolved in maven-scm-plugin version 1.9.5, but I have no luck using it... https://issues.apache.org/jira/browse/SCM-682

Capturing standards out of a class run by mvn exec:java

I would like to run a main method using Maven's exec command. I can set it up to run just fine, but the output of my class is surrounded by Maven's text.
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
...
(actual program output)
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.351s
[INFO] Finished at: Fri Apr 01 11:38:15 PDT 2011
[INFO] Final Memory: 50M/452M
[INFO] ------------------------------------------------------------------------
Is there a way to just capture just the program output and not the Maven output? Or do I need to rewrite my software to write to a file (not ideal)?
Execute mvn with the -q flag to silence Maven's output.
There's no good solution to this. It's just how the exec plugin works. You could use the exec goal and run a shell script that redirected the output.

Categories