I have an Eclipse workspace (to be more specific STS 3.6.4) with two projects:
project1
project2
Both projects are gradle projects, project1 provides classes I need in project2. Because of this I added project1 under Projects in Configure Build Path.
This works fine as long as I do not call Refresh all on gradle. Whenever I do this I have to setup the whole thing again.
I know how I could add a jar of project1 to project2, but during my development phase I do not want to build jars all the times. And I have not yet setup a repository where I could publish project1.
Is there a way to tell gradle to include .java/.class files from other proects when run from STS ?
I tried things like this:
compile project( ":project1 )
(read about this here), but this does not have the intended effect. I read another stackoverflow post but have to admit I could not get remap jars to Gradle projects to work for me.
You may read up on 'transitive' dependencies in gradle.
For a practical example you can look at
Git android proj -> depends on 'CCL' proj
AND 'CCL' depends on other stuff
In your main "build.gradle' you just include the first dependency( rest of chain of dependency is inferred using gradle transitive rules.
main proj sample
sub project
Related
I tried to find a lot of answers but could not find any which works as expected. So posting here. It can be a possible duplicate but unable to find any right answers.
Let's consider project A as my maven project and Project B as EclipseLink JAXB/Moxy library code. I am using Intellij IDE for my application.
I have a (My JAXB Project) Project A which is using the 3rd party library Eclipselink Moxy (Project B) and I believe Project B has some issue due to which Project A is not providing the output as expected. I would like to debug Project B to find the issue.
So I have downloaded the source code from Github for the Project B. Now I would like to include this Project B code from this local as my maven dependency in my Project A.
I know I can create a JAR for Project B using the mvn clean install -Dskiptests and include that JAR in my Project A but I would like to make few changes during the debug. As of now, if I make any changes to Project B then every time I need to create the JAR. The library files are very huge and it has many modules and submodules due to which it takes a lot of time (around 5-10 mins). Also, I am unable to edit the class file within JAR so need to edit the class file of Project B again to create JAR, and again add it to the project A. This is too much of a task and waiting time.
Hence, I want to know how can I add the Project B directly from local so that I do not have to create JAR every time and make changes to project B and see the changes updated directly when I run the Project A.
I tried a lot of things since yesterday but nothing seems to work till now so thought of asking the same.
In short, all I want to do is:
Add the dependency from local project so when I click on the source for my code I can open the class file from my local project because opening the class file from JAR does not provide me an option to edit.
Change version in main pom.xml of Project B to one which is not there in you repo.
install Project B using install -U command.
Use the custom version of Project B in Project A. You can also put break point now in workspace of Project A to debug.
You can make a multi module project in Intellij.
First create a maven project for project A in Intellij, then you can add Project B as an additional module in the same project.
This way you would be able to debug and hot replace the code of Project B as well.
Help related to adding a module can be found here.
I am quite new to Maven.
I have a Maven Project.
When I create execute using mvn clean -e install it creates executable jar (commounutil.jar) for my project in target folder.
Not I have another project (project2) in Eclipse which is not a Maven based project.
Project2 uses features and classes from commounutil.jar.
If I manually add my executable jar commounutil.jar in eclipse using Java build path/add external jar.
But even after adding this jar there are some errors in my project which are related to log4j.
Now when I build commounutil the dependency for log4j was already added.
Still it is giving compile time error.
Could you please tell me where I am going wrong?
Add log4j in your Eclipse classpath. Commonutils.jar,if it follows modularity promoted by maven,provides only common utils class and do not provide class related to its dependencies.
Maybe you should consider to update your second project to a maven project.
I have a project that Contains a bunch of java packages that I have recently understood are needed in a new project that I'm going to develop. I want these two projects to have the same code base so I don't have to update the common libraries in both. How can I achieve this in Exlipse?
my current set up is like this
Project1
CommonPackage
SpecifictProjectCode1
Project2
SpecifictProjectCode2
I want the following, I think:
Project1
CommonPackage
SpecifictProjectCode1
Project2
CommonPackage
SpecifictProjectCode2
CommonCodeProject
What is the best way to achieve this I understand I could extract a jar file or and include it in both project but I want to be able to debug the code and I also want to keep the code editable. Is it perhaps better to extract the code to a separate project and how do I go about doing that?
Any help is appreciated.
You can have three different projects in Eclipse: CommonCodeProject, Project1 and Project2. Then, Project1 and Project2 would have a dependency on CommonCodeProject.
To add a dependency on a project in Eclipse, go to Java Build Path and add the CommonCodeProject in the Projects tab.
Create 3 distinct projects:
Project1
Project2
CommonCodeProject
Go into the eclipse properties of Project1 > java build path >
choose the projects tab and add CommonCodeProject project to the dependencies
do the same for Project2
both project should now have as dependency your CommonCodeProject.
YES. Create third project(CommonCodeProject) as Java project and reference that new project in first two projects by navigation below:
Project1 -->Properties-->Java Build Path -->projects tab-> Add -->CommonCodeProject
Project2 -->Properties-->Java Build Path -->projects tab-> Add -->CommonCodeProject
This should serve your need.
if you would not be editing the common code then make it one project and import as a jar in the other two. or even if you are editing have 3 separate projects and build common code to create a jar which is used in other two projects
Aside from native Eclipse (as outlined in the other answers), I would use Maven+Eclipse with the m2e plugin (download this using the Marketplace). Depending on the complexity of your project, and it's application, you could even go as far as hosting something like Sonatype's Nexus with your common code deployed to as repository - this might be overkill though.
Is there an easy way to include a JAR as a dependency of a project from SVN in Eclipse. Like an Eclipse plugin or something like that?
I don't want to use Maven, it would be overkill for this project.
Update :
We have 2 projects :
Project A -> gives projecta.jar
Project B -> needs projecta.jar
projecta.jar is commited in SVN automatically
In Eclipse, ProjectB needs a dependency on projecta.jar to build.
I would like to add a dependency to the build path on projecta.jar, in Eclipse, directly to our SVN repository. For the moment, we can only do that on the file system.
Take a look at how to include a common sub-project
There's another sections in the same webpage that might be helpful...
Our software is written in Java and comprise many (7) projects.
These projects are Netbeans ant projects.
I'm considering to converting them to maven2.
Where can I find some hints for doing such thing?
Don't read that book. It will only make you confused. Read this book instead: "Maven - The definitive guide" http://www.sonatype.com/books/maven-book/reference/ .
Also, the maven site has a lot of information, but the structure is terrible so you'll need to use google to navigate in it.
Here is my suggestion:
Do this by hand, not with "automagic" "help" from the IDE. Maven integration doesn't work that good yet, not in any IDE.
Make sure you program project is divided into modules under a common umbrella module, so that each module produces a single binary artifact (jar, war,...) possibly accompanied by the javadoc of the source code behind that artifact, a zip with the source code etc. The basic principle is that each module produces a single artifact, containing all the non-test-code under that module. You can do this while the project is still built by ant.
Each module should conform to the standard maven directory layout. The build destination is under [module]/target/[output-type, e.g. "classes"]. The source code is under [module]/src/main/[src-type e.g. "java"] and [module]/test/[src-type]. The artifact consists of all the code under src/main, and none of the code under src/test, as it built to the target directories. You can do this while the is still built by ant.
Start by transforming the sub-module that has no dependencies on other modules in the project.
Now you can create the parent maven module pom.xml with artifact type "pom", consisting of one of the modules below. Make a child module for the first submodule (the one with only external dependencies), using the umbrella module as "parent". Remember that you need to specify version for the parent. Remember to add the child module as a "module" in the parent too. Always use ${project.version} as version in the child modules when you create multi-module projects like this. All modules under a parent must be released simultaneously in a single operation, and if you use this setting maven will make sure the version fields stay the same across all modules and gets updated everywhere during the release. This may make it difficult to re-use the existing numbering scheme, but that doesn't matter. You are never going to run out of version numbers anyway.
Add the necessary dependencies, and make sure you can build the parent and the child module together using the command "mvn clean install" from the parent module.
Proceed with the rest of the modules the same way. Dependencies to other modules under the same parent project should also use ${project.version} as the "version" they are depending on, meaning "the same version as this". NOTE THAT in order to build, the module you are depending on must be built using "mvn install", so that it gets deployed to you local (computer) repository. Otherwise the depending module will not be able to find the classes. There are NO source-code dependencies between modules in maven, only dependencies to built and packed versions installed in local and remote repositories. This can be very confusing if you come from ant-projects. Build from the root module until you get comfortable with this. It takes two days.
Don't use maven integration in IDEs. It is a bad idea. Use "mvn idea:idea" or "mvn eclipse:eclipse" to set up your workspace as a non-maven ordinary IDE project. The inter-module dependencies mechanisms in maven and the IDE aren't identical and will never be. Also, if you have several mavenized projects with dependencies in between, you want to have several of these in your workspace with dependencies set up between. You can do this with mvn idea:idea / eclipse:eclipse if you create a separate maven project file called "workspace.xml" (or whatever) in the same directory as parent module, set up as a multi-module project containing modules "." and "../otherproject" (only one-way reference here, no parent ref back). If you run "mvn idea:idea / eclipse:eclipse -f workspace.xml" you get a workspace with all these modules linked together. No IDE integration lets you do that. This sound like a lot of extra work, but the workspace.xml-file is really small. It doesn't have to contain all that dependency stuff and all that, only the reference to the modules you want to bind together in your IDE.
I did a succeful migration of NetBeans Ant project to Maven project using the instruccions by Joseph Mocker here: http://forums.netbeans.org/ptopic55953.html
I cite the important part:
close the project
rename the build.xml, nbproject files/folders to something so NB won't recognize them.
close and restart NB (so any memory cache knowledge of the project is gone)
copy in an empty pom from some other project.
open the project back up in NB (NB should now identify it as a maven project)
rearrange the files to follow the maven way (™)
This won't be an easy task since Maven2 expects the files to be organized in a specific way. Anyway Better Builds with Maven is a free book that should get you started. It will help you understand Maven and it also has a chapter on migration.
I discovered that the migration is not necessary. The real requirements that I need was automatic download of dependencies (libraries).
This is also achieved by Ivy which nonetheless uses maven repositories.
I solved converting project from ant to ant+ivy with IvyBeans.
I have built a script to migrate Ant builds to Maven. You can find more information here:
https://github.com/ewhauser/ant2maven
It won't help you with fixing your directory structure and or any additional Ant tasks, but it removes a lot of the tedious steps to get started.