Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
Java: How to access metafile information from maven failsafe plugin?

I want to access information like implementation version stored in the jar file. This seems to work quite well, in any technique but always based on the classloader.

If i want to test in my maven environment, of course i cannot use the surefire plugin, because this is prior to packaging in jar. Thus I must use failsafe plugin.

But then neither of the technique works, most probably, because of some dark magic concerning classloaders.

The simplest way to get implementation version is just

this.getClass().getPackage().getImplementationVersion()

which reads from META-INF/MANIFEST.MF in the jar which looks sth like

Name: eu/simuline/octave/
Extension-name: eu.simuline.octave
Specification-Version: 0.7
Implementation-Version: 0.7-SNAPSHOT

Maybe extension is not needed, what is needed is the section name which is derived from the package name in an obvious way (trailing slash seems vital;-) ). But as said, this works only in productive context, not within tests with failsafe plugin. Then the java code returns 0.7-SNAPSHOT, else it just returns null, which means according to the api docs, that the version is unknown... well.

What can I do to include meta info in maven tests???

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I did some research on the failsafe plugin. For example running with

mvn -X verify

unveils

INFO] --- maven-failsafe-plugin:3.0.0-M5:verify (run-tests) @ javaoctave ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M5:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@277050dc]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:3.0.0-M5:verify' with basic configurator -->
[DEBUG]   (s) basedir = /home/ernst/OpenSource/OctaveInJavaGit/octaveInJava/javaoctave
[DEBUG]   (s) reportsDirectory = /home/ernst/OpenSource/OctaveInJavaGit/octaveInJava/javaoctave/target/failsafe-reports
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@1416a80a
[DEBUG]   (s) skip = false
[DEBUG]   (f) summaryFile = /home/ernst/OpenSource/OctaveInJavaGit/octaveInJava/javaoctave/target/failsafe-reports/failsafe-summary.xml
[DEBUG]   (s) testClassesDirectory = /home/ernst/OpenSource/OctaveInJavaGit/octaveInJava/javaoctave/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG] -- end configuration --
[DEBUG] Failsafe report directory: /home/ernst/OpenSource/OctaveInJavaGit/octaveInJava/javaoctave/target/failsafe-reports

Note the testClassesDirectory. I thought that the plugin accesses the jar created in the preceeding lifecycle phase package
but obviously this is not true and there seems to be no way to do so. Thus all the stuff does not work.

I filed a feature/enhancement request to fix that.

No idea whether they like my idea.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!