relative path from pom.xml does not get resolved when using git - java

I have a strange issue which I guess comes from git. In one of the poms in the projects I'm trying to build there's a call to some source-generator with a config-argument like ${project.build.sourceDirectory}/../resources/config/variables.properties (Note the ../ to get to some upper directory). Everything was fine until I merged the master to the branch. This is when the build of this module started to fail with
[ERROR] Failed to execute goal some.package.maven.plugins:runtime-configs-generator:1.1:generate (generate-runtime-config) on project runtime-configs: /home/user/development/workspace_primary/configs/runtime-configs/src/main/java/../resources/config/files.properties (No such file or directory) -> [Help 1]
my setup: I'm locally using git and dcommit to a remote svn repository.
It seems like the file can't be found anymore. Strangely there are no changes in the relevant parts of the files after the merge.
I next tried to merge by using svn just to make sure the files are exactly the same as with the git merge.
Then I commited the merge I did with git to the subversion repository and did a fresh checkout using svn. It builds with no problem. However when using the git repo I still get the same error.
I tried to delete the local git branch and recreated it again from the remote refs. Still it does not build with the error. First I thought it might be an issue with my terminal/shell (terminator with zshell) having a problem with relative paths, but then why it built before the merge and why it builds from the svn checkout but not from the git directory? When I replace the relative path in the pom.xml with something like
${project.basedir}/src/main/resources/config/variables.properties
it also runs from the git directory though.
Can anyone explain this weird behavior, I'd love to understand what I'm missing.

Something must have been broken in the git repo... I restored an older version from a backup, did git svn fetch && git svn rebase and it's working fine now

Related

Creating new local git repository from different versions of a java project files

I am new to git, I have many versions of a project stored in my local computer I wish to do the following
create a local repository in git from these versions with differently named root directory
see the differences between the versions
pl. help
Create a new directory, henceforth x, and cd x. Then run git init. This will start a new empty git repository inside the x directory. A git repository is a folder that has a .git subdirectory.
Copy the files from the first version of your project, paste them inside x.
Create a .gitignore file inside x and tell it which files of the project you do not wish be tracked by git. See here for more info.
After you're done, run git add -A to tell git to track all the files in the directory and prepare them for committing (this will add all files except for the ones mentioned in .gitignore).
Now run git commit -m "This is the first version of my project"
Now for the second version - completely overwrite all the files inside x with the files of the second version (by deleting everything except for .gitignore and .git and pasting the files of the second version). Then performs the commands similar to before:
git add -A
git commit -m "Second version of my project".
Repeat these steps for all versions - overwrite files, git add, git commit, repeat.
You now have a local git repository, with each commit corresponding to a version of your Java project.
You can see the differences between the versions using the git diff command or a Git GUI tool of your choice tool which allow you to explore your newly created repository.
You can now also upload your repository to a Git hosting service of your choice (popular ones being Github, BitBucket, GitLab and more) by creating an empty repository inside those services and adding it as a remote in your local repository and pushing the master branch (thus syncing the local copy of the repository with the remote host).
Note that this could be automated if you have a lot of versions, but such automation would largely depend on how your current "folder versioning" is structured, so this is up to you.

Merge local Java project to existing git repo

I have checked out the source from a git repo, because i was forced to use someone elses svn repo for a while, and now i want to re-check in my source in the original git repo. We are using eclipse (STS) for the project. The perfect solution would be to check in the changes made during this time into a new branch and then putting back together everything.
Does anyone know how I can do this?
If you have your changes made in one folder, you can use that folder as a working tree in order for your git repo to detect and add those changes.
cd /path/to/git/repo
git --work-tree=/path/to/other/repo status
git --work-tree=/path/to/other/repo add .
Then you can commit and push normally from your git repo now updated with the latest changes from the other repo.
Note: that is a command-line solution: once done, you can resume working in Eclipse.

How to configure a project imported from GIT to be a Java project in Eclipse?

I've imported a project from Git in Eclipse using this method:
File > Import > Git > Projects from Git > Next > Clone URL .
At this point I inserted the URI like this https://github.com/mygituser/My-Project .
Then my user and password, and the project was imported.
The problem is that Eclipse didn't recognize it as a Java project, and I really don't know why.
As consequence, I can't see errors or warnings on my project and neither use autocomplete, I'm getting this message "This compilation unit is not on the build path of a Java project".
Also, right click on My-Project > Build path shows the message "No actions avaliable".
If you need more information to help me, could you ask me on comments, please?
I appreciate your attention!
Most people don't include build files in repositories, only source. What you need to do is create a new Eclipse project the create a Git repo on top of that:
Create a new Eclipse project, and go to it with your terminal.
git init to initialize a repo.
git remote add origin https://github.com/mygituser/My-Project to add the remote.
git pull -u origin master to pull the changes.
Also, make sure that when you commit, you don't add build files that the author kept out. You can do this via a .gitignore file. Simply take this file and add it to your project directory.
This method applies to most Git repositories, as build and compiled files are usually left out.
Note that this method requires that you install Git for command line (or Git Bash). You can get Git at their website.
Since you already have the source code downloaded from the git repository, you should be able to create an Eclipse project from the existing source code.

Switch to older version of Maven

I am trying to build a project using Maven but I don't know Maven.
Anyway I had a problem and I found in a link to use an older version of Maven. So I did, since the instructions for the project were about 2.0.9 anyway.
But now I am not sure how to proceed. I see under my user.home directory a .m2 folder with a repository directory.
Should I delete this or not?
The .m2 folder contains the downloaded artifacts and some other repository info, which do not depend on the used maven version. So you dont need to delete anything, just use the maven binary of your choice.
EDIT: the contents of the artifacts - .jars, .poms, .boms etc. are defined by the artifacts themselves which are the accesible through repositories/catalogues. The .pom of your project references the needed artifacts. The maven binary downloads the artifacts (and does many other things which are OT here) to your local cache - the .m2 directory. The point is, no matter what version of the maven binary you use, the artifacts remain the same.
You surely can delete your repository. As long as you have an internet connection maven will simply download the artifacts again. But there is nothing to be gained by the removal except a longer initial build time and some traffic.
Sometimes it does make sence to delete certain metadata from the repo, like the .lastUpdated files. It is only advisable if maven is unable to find a dependency which you know for sure is in your repository. You can then run find ./ -name "*.lastUpdated" -exec rm {} \;.

Android Eclipse test projects cannot be used with a project being built in an Android build tree

An Android Java project placed in a git repository and built in an Android tree in /packages/apps needs to have the project files located at the root of the git repository.
This is problematic for creating a complementary Test project, which should ideally be included in the same git repository so commits are atomic for both code and tests. Eclipse gets very unhappy if you include the Test project as a subdirectory.
Is there an appropriate approach for dealing with this other than creating a second repository?
I dont know git but this seems to be a code organization problem rather than git issue. I think I would create a workspace and then have the application and test project as sub projects within that workspace, like this
/packages/apps/<product-name> - This is the workspace
/packages/apps/<product-name>/app-name - This is the application
/packages/apps/<product-name>/app-name-test - This is the test project for the application
I don't use git inside eclipse. I have my repo cloned at ~/work/repo and have 2 subfolders one for the actual project and one for the test project. Then inside my workspace i have 2 symlinks that point to the folders inside the repo folder. Eclipse thinks they are both normal projects and doesn't care about the repo management. I just go to command line and "cd ~/work/repo; git add .; git commit; " and i can commit both test and code at the same time.
Hope that helps

Categories

Resources