Maven install or clean depending upon changes - maven

We have a huge set of modules in our project and therefore we use mvn install to save time on builds. But, it doesn't seem to handle file deletes very well. It doesn't delete the deleted files from the target during compilation.
Is there a way for maven to perform a "clean install" when there are deletes or even changes to the module. And perform "install" if there are no changes.
Or, is there an option in install to detect file deletions and update the target accordingly?
Thank you.

Related

Can you modify files in a repository right after issuing maven compile install?

For projects which take a long time to build, can you issue the maven compile or maven install commands and then continue making changes to the files in your repository, without these changes affecting the outcome of the maven install command?
Is a snapshot automatically taken when the command is issued? If not, is there a way to request that maven take a snapshot of the project when a command is issued, so that you could continue making changes after that snapshot?
If you build locally, you should not be changing files while you build because you might break the build.
If you build on a build server, it depends:
If you run a clean package or clean install, then there is just one checkout at the beginning. After that it should not be a problem to make further commits.
If you build a release with Maven release plugin, you should probably be more careful. I haven't actually seen any problems in nature yet, but since the Maven release plugin commits to git/svn itself, you might cause problems when committing during the build on the same branch.

Out-of-source builds in temporary directory with Teamcity

I'm using Teamcity to build a CMake project. I'd like to leave Clean all files in the checkout directory before the build off, so that it doesn't have to keep re-fetching all the source for minor changes. Is there a way I can specify the CMake working directory to be in some temporary directory that Teamcity will create for me, and then delete when the build is done?
I thought %system.teamcity.build.tempDir% might do it but there doesn't seem to be any documentation for it, and I think that might just be the directory where all builds go.
%system.teamcity.build.tempDir% is fine. And so is %TEMP% actually (on Windows, or %env.TEMP% in TeamCity-speak): the agent overrides the env var and uses a clean temp directory for every run.

Will I ever run into problems if I don't clean before I build?

I've written a git pre-commit hook that aborts the commit if my xcode project fails to compile.
It does this by running xcodebuild with the appropriate settings for my project. If the xcodebuild returns a non-zero status then you can't commit your changes.
Here is the xcodebuild command I'm running:
xcodebuild -project MYPROJ/MYPROJ.xcodeproj -target MYPROJ -configuration Debug clean build CODE_SIGN_IDENTITY='iPhone Developer' >/dev/null 2>&1
What I want to know is what issues will I run into if I remove the "clean" from the build command? I have a vague understanding of what "clean" does: remove previously compiled objects which will cause the following build command to build the entire project from scratch.
However, a full build takes a long time on our project whereas if we don't do a clean and haven't modified a lot, it can only take a few seconds. I'd like to keep our pre-commit-hooks fast and lightweight but I'm worried the build will get in some weird state and prevent a developer from being able to commit even though their code is fine.
Will I run into issues if I don't clean before every build for my pre-commit hook? Will it possibly incorrectly report a build error in some cases or get out of whack if I don't clean?
If you want to have certainty that your commit compiles, you should clean before building. Sometimes libraries and resources can get messed up, that's why the clean command exists. You want to make sure that someone who would check out that revision could compile the project with no issues. You can't guarantee that if you might have some leftovers from previous builds, such as old resources.
Imagine using an image for your GUI. You compile your app and it works. Then you restructure your resources a bit and somehow end up removing the image from the project. If you run the app again, it can still load the old image if you don't clean the project. So it will work for you, but not for someone with a clean build.

Making sure maven is running from scratch with a clean repo

I am pretty new to Maven and really not trying to fully learn it right now, just trying to install my java project.
I get some errors (it is from a Hadoop Crunch project) but the errors feel like they are referring to my older code that was doing a division and could be div by zero.
So anyway: Currrently I am dong mvn clean install but looks like there is something its cache still? is there a more powerful way of doing this such that I make sure nothing is coming from its cache, etc?
Look for your repo at C:\Users\youruser\.m2 or ~/.m2, you can delete that whenever you want but it will cause a "Download the Internet" the next time you do something.
That's obviously not the solution for daily use, the mvn clean install does compile and put the binaries of your project in your local repository from scratch, but if you have SNAPSHOT dependencies to separate projects (I'm not talking about submodules, I mean projects in some other directory) then you would need to go to those projects first and do mvn clean install there first so that your local repository has the latest binaries.

Maven re-build and deploy

I'm new to compiled web development, and I'm just trying to figure out the build/deploy process.... I've done:
mvn clean install
on a project, which built and deployed the project and now I can see it. If I want to make changes to the codebase, do I really need to run mvn clean install again to re-build and deploy the changes or is there a way to do a quicker build without using a "proper" IDE?
I'm using vim/gvim
Thanks!
Maven already handles the dependencies and only re-builds the necessary files... unless you throw away all previous build artifacts with clean! You should only need to use clean when you run into problems, or when you have checked out a different version from version control. Usually, mvn install should suffice.
You can integrate that with Vim; the simplest is to
:set makeprg=mvn
and then trigger a build with :make install.
Plugins build on that simplistic setup, e.g. check out:
maven-plugin
maven-ide

Resources