Spring boot actuator sample not working - maven

I checked out spring-boot project from:
https://github.com/spring-projects/spring-boot
and after running spring-boot-sample-actuator with mvn spring-boot:run and navigating to http://localhost:8080/info
I see:
{version: "#project.version#", artifact: "#project.artifactId#", group: "#project.groupId#", name: "#project.name#"}
It seems that Automatic property expansion using Maven (also exlained here http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-application-info-automatic-expansion)
is not working.
What am I missing, how to make it work?

The thing is that the spring-boot-maven-plugin tries first to be able to make the developer productive.
In short, when a path/file is both present in target/classes and in the sources or resources (such as application.properties), it will delete the contents under target/classes.
This is clearly visible here.
So as it is deleting the target/classes/application.properties, and adding the project resources to the classpath (so adding here src/main/resources/application.properties), you can only get the non-filtered file.
Fortunately, you can disable this behaviour by adding this flag to the command line:
-Drun.addResources=false
or in the POM plugin configuration
<addResources>false</addResources>

Related

Application.properties ignored when creating a Maven submodule

After creating a Spring Initializr application, I ran it using server.port=9090 in the application.properties and it worked.
After creating a module (from IntelliJ), suddenlty without doing anything else, the application.properties is ignored and it tries to run again on the port 8080 as default.
Here is the structure:
Project common is empty.
Just the maven structure.
Thanks!
LE: Seems that it has to do with the packaging of the children module. Paste from my previous comment:
what I have found now is that because of having pom in all the children, this strange behaviour is happening. The resources, are not taken in consideration. If I remove the packaging tag, they are taken in consideration, BUT, the maven clean install will complaing on that child, because it cannot find the .jar dependencies to the other children (because they have pom packaging) ...
LLE: In the end I have found the problem, and I will leave it here, maybe someone else will run into it.
So, my issue was that besides the parent pom.xml that had POM packaging, there were also childer with the same packaging. When I have removed all of them from the children modules, everything worked fine, including the maven-clean-install.
In one word: POM packaging only for Parent module

Gradle refers jars but they are not in POM nor in the code links

We migrated our maven code to gradle. When we build, we are getting error as Could not resolve all files for configuration ':***-war:compileClasspath'.
Could not find mockito-core.jar (org.mockito:mockito-core:2.8.9).
We are not referring to this jar itself.. neither we are able to locate in our code nor in pom...
How to figure out?
how to configure gradle to compile code if jar doesn't exist and pom exists in the repository or locally ?
If you can't work out where it's coming from and you don't use it at all, then you can exclude the dependency from all the configurations:
configurations.all*.exclude group: "org.mockito", module: "mockito-core"
If the dependency isn't appearing in the dependency report, then I'm somewhat at a loss as to why Gradle is complaining about it. The only other option I can think of is that some plugin is adding it in a non-standard way.

How do I verify that my eclipse project is effectively using tycho

I am transitioning to Maven-Tycho and was dealing with many errors. I seem to have gotten rid of all the errors but when I look into the pom.xml file I see maven-install-plugin, maven-compiler, maven-release plugin, etc and no mentions of tycho like I see in my tutorial. Did I do something wrong how do I make sure that my project is using maven-tycho not maven only.
http://www.vogella.com/tutorials/EclipseTycho/article.html
Any changes can be made in the pom.xml tab. The Effective POM tab is read-only, it just shows what Maven constructs when it parses your project. It's composed of your POM and its (grand)parent POMs. The Effective POM does not exist on your filesystem per se, it's generated on-the-fly whenever your run a Maven build - hence why the view is "read-only". You can change to tycho-compiler by modifying the pom.xml file replace maven-compiler-plugin with tycho-compiler-plugin. Make sure you add tycho to your eclipse environment

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

What is the purpose of the # symbol in <groupId>#project.groupId#</groupId>?

I'm trying to run 'mvn clean install' in a sub-module of a multi-module project. The project is Jacoco but I assume it's more an issue of me not understanding how Maven is being used here than an issue with Jacoco itself.
https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-site/pom.xml
I get the following error:
[ERROR] Plugin #project.groupId#:jacoco-maven-plugin:#project.version#
or one of its dependencies could not be resolved: Failed to read
artifact descriptor for
#project.groupId#:jacoco-maven-plugin:jar:#project.version#
I see the following in the pom:
<groupId>#project.groupId#</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
I'm not familiar with using the # symbol in #project.groupId# although i assume it is somehow supposed to get substituted at runtime.
I can run Maven from the top level pom and I even see [INFO] Building: it-site/pom.xml in the log but a target directory is not created there.
A nudge in the right direction would be appreciated.
This probably has something to do with the pom file here: https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/pom.xml
It is using a plugin called the maven invoker.
The Invoker Plugin is used to run a set of Maven projects. The plugin can determine whether each project execution is successful, and optionally can verify the output generated from a given project execution.
And if you read about filtering files with this plugin, it mentions:
POM files selected by the include/exclude patterns. The tokens to be filtered must be enclosed in #...# to avoid interferences with Maven's normal POM interpolation, i.e. use #project.version# instead of ${project.version}.
Regarding why the Invoker Plugin and filtering is being used here...
The Spring Boot documentation provides some relevant background on why that is. Although the docs are for Spring Boot, i think it applies to testing all plugins (which Jacoco is).
Multi-module Maven builds cannot directly include maven plugins that
are part of the reactor unless they have previously been built. ...
The standard build works around this restriction by launching the
samples via the maven-invoker-plugin so that they are not part of the
reactor.
The sample application are used as integration tests during the build
(when you mvn install). Due to the fact that they make use of the
spring-boot-maven-plugin they cannot be called directly, and so
instead are launched via the maven-invoker-plugin.

Resources