How to configure git repo with multiple java projects in eclipse - java

I'm following this tutorial: http://spring.io/guides/tutorials/rest/ to get familiar with spring/REST. However, the git repo (git clone https://github.com/spring-guides/tut-rest.git) has many individual java projects each with their own gradle build. I'd like to edit the code in Eclipse, as that's the whole point, but this hasn't proved trivial.
So far, I've created a general project for the git repo, and then separate java projects for each of the folders from the repo, linking the source in my java projects to the source/test folders in the repo. This has worked great except that I don't have the spring jars in my dependencies for the java projects, I get a ton of errors as well as lose the nice autocomplete of function names, etc.
What is the correct way to fix this? It seems like there isn't a good way to install the jars for spring in each java project without using maven or some other build tool, which seems redundant and inefficient since I can build the source from the repo project. If this is the case, should I make a build for each separate project even though the idea for the tutorial is that they each come with gradle?
Thanks for your help, and please excuse the slight open endedness of it--I'm not sure I'm on the right track.

Related

Java add .jar files automatically as a a Library

I am creating a java project in IntelliJ (without maven or grandle). The project uses an external library, whose .jar file I’ve put into a /lib directory. After that I had to select at the /lib folder “add as library” to use it.
Now I want to push the project to GitHub, so that some people (who are using IntelliJ as well, but in different versions) can use the project.
Now my question:
Is there a way, that they do not have to do the step “add as a library” themselves?
My first idea was to push also some parts of the .idea folder to GitHub, but I am not sure which ones to push and if that could actually work (especially with different versions of IntelliJ).
Do you have any idea how to solve this issue?
If you are using only IntelliJ for building the project, then yes, you should push the .iml files from the .idea folder (or where they happen to be), since they contain the dependencies configured in IntelliJ.
Note, that projects with multiple contributors typically use a build tool like Maven or Gradle.
This is a special build requirement, which I would use Gradle for. With Gradle you can look up a given folder, like /lib and use all .jar files as dependency.
See Gradle example about exactly what you want.
IntelliJ is handy when you do something simple mostly for learning, but if you want to be a professional one day I highly suggest looking into Gradle. It has a learning curve for sure, but you can achieve such simple tasks like this in your question relatively simply. And as you seem to know, pushing .idea to the repository is really not the nicest thing one can do :)
Just a small additional note: Gradle solves the "different version" problem by including a "Gradle wrapper" inside the repository, so everyone cloning the repository will have the same copy of Gradle as well, so the same build process is guaranteed for all contributors.
Also, when I started programming I downloaded the dependencies and used them as jars. But if you learn at least Maven, and your dependency is uploaded to a repository like Maven Central, you can just paste a line of code into your pom.xml (Maven) or build.gradle (Gradle) and you are good to go :)

Cleaner and idealistic way of migrating ant project to maven

Trying to migrate an ant project to the maven project and was able to use translate to the maven project feature of the eclipse. Though I have an idea of working with maven projects so far, but still would like to know if there are any best practices to follow while migrating it.
Also, would really appreciate if anyone can help like how to set up the same on bamboo that would be ideal for all the working developers.
The steps achieved so far are :
Created pom.xml with all the required jars and repositories.
Created a local .m2 folder with dependencies present and installed.
I would like a meaningful transition from ant to maven. I know how things work on local but when it comes to deploying it to bamboo, I am a bit confused with so much distributed information on the internet.
Any specific leads would be really helpful

IntelliJ project where each module has it's own git repository

I am a new IntelliJ user (I've used Eclipse for many years). I'm having a hard time wrapping my head around the-project-is-a-module concept in IntelliJ, since this does not hold true in Eclipse. The main issue I'm having is that I am using my top level package as the project in IntelliJ. I would like this top level package to be in a git repo. I would also like all the dependencies of this package to be in their own respetive git repos. When I check these packages out into my project, a do git status on the top level package, all of the dependencies show up in the untracked files. This behavior seems incorrect to me. How can I fix it?
Thanks!
Edit:
To summarize the clarifications in the comments:
I would like to support hundreds of libraries any of which could change at a time. The dependency graph will also be frequently changing. For this reason, having one git repo or constantly updating .gitignore files is not maintainable.
Currently, I'm using Maven to manage dependencies but I'm open to using whatever is best suited for this job.
Finally, I would like to check out any library into my workspace and modify it and, if possible, have Intellij reflect my local changes when running code as if my local code were already built into the dependency graph. A type of local override if you will.
IntelliJ's directory structure places all of the modules in their parent project's directory. If you are developing libraries which are shared between several other projects, importing the library as a module is probably not the correct solution. Instead, you should treat each library as its own independent project and make "releases" using a build tool such as gradle or maven. Then your projects can treat the libraries the same way they do third-party libraries and use the build tool to import the library.

Sharing Code between eclipse and intellij

I work with a partner in java programming, I use intellij and he uses Eclipse.
Is there a way that we can somehow mutually share our code with each other so we could work on the same code each in our own time?
Thanks
There is that possibility using GIT or another Code repository. Look at https://github.com/
or https://bitbucket.org/. There is also very helpfull article.
To be also independant you can simply integrate your code with Maven, both incellij and eclipse can import project based only on pom.xml file created in maven setup.
In this your should use repository when there are more than one programmer on a single project whether you are using even same IDE. SVN will be one of the choices for repository
Given that you guys need to implement version control, one important aspect of co-operating together is to keep your codebase IDE-agnostic.
Thankfully, with java and maven there is an easy way to do this.
Firstly, commit to building your project with a build tool such as maven. Therefore, using this example, the pom.xml is the master configuration file for your project.
In contrast, your "project" files (either your .idea folder for intellij or your .project, .classpath and related files for eclipse) should not be checked into version control at all.
You can then add "ignores" to your VCS so that IDE-specific configuration files are not checked in - this way you won't interfere with each other with IDE-specific things.
Then, it is relatively easy for both of you to share a maven (pom.xml) based project with each other, and to configure your IDE independently from each other (i.e.: locally).

IDE + manual build process

I will ask my question short and sweet, is there any formal way to write code using IDE and then build them using manual build process.If anyone has good links on internet, it is better to give
I believe it's easy, and what is more important - convenient, in cases when your IDE project is based on some external build model e.g. Ant, Maven, probably SBT for Scala. In this case it's easy for external build to be synchronized with IDE. Also it's important whether your IDE monitors underlying filesystem changes inside project folder, as I believe it's going to be quite pain-full to click "Refresh" or something similar every time you build.
Popular IDE's provide options to import project from external models like Ant and Maven.
Personally I use this approach in one of my projects with Java, Maven and IntellijIdea.
Yes. Use maven. It has plugins to all popular IDEs. So, create maven project, write pom.xml, run mvn install and then run mvn eclipse:eclipse (if you are using eclipse).
This will produce .project and .classpath. Now open eclipse, define classpath variable M2_REPO and import your project.
M2_REPO should be defined only once and should refer to local maven repository that is typically located under USER_HOME/.m2/repository.
For more details see documentation of maven.
I did not know this and always spent a lot of time synchronizing my IDE and ant build.xml. But now I am using maven and can forget about this hard work.

Categories

Resources