New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Maven/Gradle profile(s) as default Spring profile(s) #3224
Conversation
6ffabb3
to
a9a5336
Compare
I know for sure that .original us required for AWS but not sure of heroku
|
And yes this should be part if 3.0
|
processResources { | ||
filesMatching('**/.build-properties.xml') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to have an xml for this its kind of ugly :( cant we do the same to the profiles .yml file? Or using the application.yml file?
I had a look and im not sure. I dont like having additional xml and a class for this, isnt there a simpler way? Im not sure if this additional complexity which is a bit non standard for normal spring apps IMO is worth the value provided which is letting the user run without passing a profile. Any way we need to see if there is any simpler alternative to this |
Absolutely agree that this is not very pretty! This is why I made it a hidden file -- slightly embarrassing :-) I have tried to find a nicer way to do this, but couldn't find one. If anyone has ideas... Please let me know! For what it's worth though, putting this in the application.yml definitely won't work; it has to be done before spring parses those yaml files, because it will be used to determine which of those to load. |
Of course the same mechanism, with almost no extra effort, could now be used to deliver more properties from build to runtime. For my own application I'm thinking to include build tool (maven/gradle), build date, git revision (hash of latest commit), ... |
May be lets take some time and see what can be done, this is not a blocker Thanks & Regards, On Sun, Mar 20, 2016 at 3:52 PM, Erik Kemperman notifications@github.com
|
lets do this after 3.0 so im gonna put this on hold |
Well, despite maybe being subject to a better implementation, I think that it functionally accomplishes a useful detail -- and it shouldn't get in the way of anything else, I don't think, contact surface with rest of the code is unobtrusive and limited to the main and webxml classes. But fair enough, please let me know if / when to pick this up, or if anyone sees better ways to do this! |
Maybe I should mention one other implementation I considered, but decided against: the |
lets wait and see if someone has a better idea Thanks & Regards, On Sun, Mar 20, 2016 at 5:39 PM, Erik Kemperman notifications@github.com
|
b959cef
to
67f0719
Compare
Minor FYI: removed a now unneeded import from ApplicationWeb.xml, and rebased onto latest master (had to adapt to a commit to make gradle/protractor test pass). I would still love to hear if anyone has ideas on how to improve on this implementation! |
67f0719
to
42b3eaf
Compare
Travis is flaky; restarted the failing test and now it passed. |
@jhipster/developers guys we need to progress on this, any comments from you guys? |
42b3eaf
to
166e8aa
Compare
Looks good to me. I have no feeling against xml, in case it stays as small as possible |
I'm in favor of including this. It will be great for on-boarding because users would expect the app to start in prod when packaging a jar for prod. Also if spring.profiles.active always take precedence it should not cause issues. |
166e8aa
to
baa2365
Compare
Rebased again and fixed an inaccurate comment in BuildProperties.java. |
Im not a spring boot expert but I was wondering. Spring boot does support loading stuff from an external may be we could figure something out using that and the springs various annotations to load specific stuff based on things available in classpath or environment. Thats how spring does most of the autoconfiguration magic isnt it? |
Well, I'm no spring expert either, so maybe I'm missing something... But my thinking was we can't use spring's autoconfig voodoo for this particular case, because we need it done before spring looks for external I could change it from But I think we'd still need to load it manually, and provide a fallback for unsubstuted values, which makes me think having a separate class ( |
@jdubois @erikkemperman Ok so I did some more digging to see what was causing the original issue in our setup where the below
in So I guess the solution here is very simple and much cleaner. we can set the below 2 properties in our
and we need to replace So this means we wouldnt need an xml and a I tried this on a generated project and seems to work. I foresee once issue with replacing content using maven/gradle with this PR as well as with my approach above. When we run the build with a specific profile it will replace the placeholder in the file, if we run the build with another profile later there is no more placeholder to replace. @erikkemperman how did you handle that, I dont see anything specific for that in the PR? |
@deepu105 That sounds good! So you figured out how to call Note that maven/gradle don't change the file itself, but substitute while copying to Without the properties class, though, how to handle fallback when running without maven (in IDE)? |
Also, will it still be possible to override the profile after the war is generated (see @mraible's comment above)? |
@erikkemperman we dont have to call If maven/gradle doesnt change the source then it should be good, then we have to pass the profile as the I think we cant use the dev war for prod and vice versa due to the PR you did to move stuff to the target folder. Anyway we discussed that and was decided that way. So no point going back on it again. I agree it was a nice feature but it was also adding a lot of bloat to the built package |
@deepu105 Ah, sorry, I had missed you put Maven/gradle doesn't change the source, at least in my setup (I hiked along with how it replaces You're right about the front-end implications of But as long as the override with About fallback when running in IDE, yes we should then set All in all I absolutely agree that this sounds like a much cleaner way to achieve the desired effect. Kudos! If / when you have a branch that you'd be willing to share, I would love to try it out! |
BTW seems like the |
No need to shout :-) (But I see what happened there, with the hash tag making it H1) |
LOL. Ok found a way to set the default profile elegantly :) @erikkemperman I can do a PR with the settings to change the way default profiles are done. But im a gradle guy and my maven skills suck, so could you help to do the replacing |
This looks much, much better than the XML file :-) |
@deepu105 I think something like this would do the trick. It assumes that we also change the delimiter for the logback level, so beware that that would have to change in gradle as well. Alternative, we could use both Either way, I trust this gives you all you need to complete the PR? If not, let me know. @jdubois Agreed, if Deepu's approach works it is much better. Thank you guys so much for not giving up on this!! |
@erikkemperman I will try today else I can do only next week as im going on a short vacation tomorrow |
@erikkemperman yes and I'm very happy :-) |
Ill commit what i did so far in a PR any way, so that you guys can try it out if required.
But this doesnt seem to be triggered during bootRun or when run from war, when is this trigerred? is this for deploying to tomcat/jboss etc? |
@deepu105 to be honnest, I'm not sure if it's being used :-) |
Its working without this file, when I run from IDE, bootrun from console or when run as |
@deepu105 then kill it, KILL IT 💯 |
@deepu105 @jdubois I wondered the same thing, when I was working on this PR, but if I remember correctly this is indeed (only) called by servlet containers as an alternative to web.xml. The logic is completely analogous to the main application class, though, so not really hard to keep both equivalent. |
@erikkemperman that's also what I remember... stupid app servers! Then we might need to keep it, and validate that it works well with this new setup |
The documentation for the superclass
|
Ok ill try to check it |
First PR is done. we need to do the property replace from maven and gradle. for gradle its very easy as I said earlier. But I wont have time for few days for that |
@erikkemperman @deepu105 as work as begun on the property replace, are you OK to close this PR? |
Yup, I guess that's the way to go. Closing. |
Sorry for the many PRs, I will stop now :-)
As discussed, among other places, in issue #3180, this promotes the profiles used with Maven/Gradle to be the default profile(s) in Spring -- unless an explicit
spring.profiles.active
is given, of course.This means that
mvn -Pprod package && java -jar target/foo.war
does what you'd expect without the need for arguments. Likewise when deploying the war.It might be too late for the 3.0 release...? Although I kind of feel that it belongs together with the change that made the
dev
andprod
assets mutually exclusive in the war file.I did not change the default profile to be different for
run
orpackage
goals, as was suggested: I am not sure this is even possible with Maven.I briefly looked into changing the war filename depending on the profiles used, as was suggested in the linked issue, but the generators for AWS, Cloudfoundry, and Heroku seem to only expect a single war file to be present: Cloudfoundry and Heroku use
*.war
, while AWS (arbitrarily?) picks the last*.war.original
file returned byfs.readdirSync
.By the way, shouldn't the uploaded war for those generators always be the
.original
one, also for Heroku and Cloudfoundry?