Is there a way to create a gradle java project in IntelliJ with a client and server side that share a class library? Something similar to how Visual Studio allows multiple sub projects that can have their own .exe build for each and a .dll for the library.
Example:
+ Project
- Client (Separate .jar built)
- Server (Separate .jar built)
- ClassLibrary (used by Client and Server)
Yes, use File | New... | Module action and select Gradle type for the new module.
By default IDE will add this Gradle module to your project as a child via include '<project-name>' directive in settings.gradle file.
Then in your main/parent project build.gradle script you can add this Gradle project as a dependency: implementation project(':<project-name>'). See Gradle documentation for Project lib dependencies for more information.
Related
I am developing a project A (Java Maven) which uses a library B (a JAR file)
I have the source code of library B, and I want to change code in project B, while it's used as library for project A.
Is that possible in Intellij to replace a JAR library by its source code ?
I'd configure a multi-module Maven project with the parent aggregate pom.xml and 2 sub-modules: for the app and for the library with their own pom.xml files.
Define a dependency on the lib module for the app module. IDE will resolve such dependencies via the sources and you will see the changes in the project instantly without the need to compile. Refactorings will also work across the modules so that you can rename a method from the usage in the app and it will automatically rename it in the lib.
I created a library project in Android Studio (currently 0.5.2) by choosing File > New Project... > "Mark this project as a library".
I have two other non-library projects that I would like to add a dependency to this library project.
-My Library
-Project 1 (depends on My Library)
-Project 2 (depends on My Library)
My goal is to keep each project independent and avoid duplicating modules/code. How can this be done without copying the library module into the other projects?
Update:
Android Studio 0.6.0 allows you to Import a module, though, this simply copies the module source into the Project.
You can also refer to a library outside of your project folder using the project().projectDir property. If your external library is relative to your project like so
- MyLibrary
- library
- MyProject
- app
in MyProject/settings.gradle
include ':library'
project(':library').projectDir = new File(settingsDir, '../MyLibrary/library')
in MyProject/app/build.gradle
dependencies {
compile project(':library')
}
This is very similar to this question:
Sharing an Android library between multiple Android apps using Gradle
Instead of pushing to maven central you can push to your local maven repository (mavenLocal() in build.gradle)
Another route (if you don't want to deploy the library somewhere) is to use your VCS and check out the library within your project. Git has submodules for that, Mercurial has subrepos and SVN has external to name a few examples.
Then add it to your Gradle build using a project dependency.
I use Gradle to configure my new projects and import them into eclipse.
The project A (wtp) depends on project B (pure java).
Root
A (web application)
B (java dependencies)
I try to use gradle's multi project settings. In Project A build.gradle I've added
compile(project(":B")).
Inside eclipse I'm able to use the project B class, but I'm not able to run it in tomcat because of the following error:
"Could not publish to the server. Path for project must have only one segment."
Do You have any suggestions?
Suppose I have an Android application project in IntelliJ Idea with Gradle. Call it MyApplication.
What I want to do is to add a plain java library module (not Android library project) as a submodule to MyApplication. Lets call this module a testlib.
And then when whole project is built, I want this module compiled to jar and included to /libs folder of MyApplication.
What I tried: I've created a submodule testlib and included it as a dependency to MyApplication, but I get a following warning:
Warning:Gradle: module 'testlib' won't be compiled. Unfortunately you
can't have non-Gradle Java module and Android-Gradle module in one
project.
Is this even possible?
If you've created your project in IntelliJ as an Android-gradle project, then when you go to the "Add new module" window you should see an "Gradle: Java library" option like this:
IntelliJ IDEA does not support Gradle and Non-Gradle modules in one single project. A comment from JetBrains in their forum states this clearly.
The solution is to either convert the Maven modules into Gradle
modules or split the project in two. With the latter approach, if you
build the plain java library module with Maven before building the
Gradle project, you will still be able to use it as a dependency in
the Android application project.
Beware of using different Java language source levels in multi-module
Gradle projects. IntelliJ IDEA does not handle them correctly due to a
bug in either IntelliJ IDEA or Gradle. (There is a pending discussion
whether this should be fixed in the IDE or Gradle.)
I have a nested m2Eclipse project in Indigo. The parent project contains the src folder that is used by the nested modules (see structure below).
parent
src
pom.xml
module1
pom.xml
module2
pom.xml
Running mvn package from the Maven run configurations builds all the modules, so dependency management appears to be working. However, I don't have a MAVEN DEPENDENCIES folder and I can't use Java content-assistance or any other Java Project capabilities on any of the source files. I tried converting the project to faceted form and adding the java facet, and that didn't work either.
It is because the parent is not a java project but a pom project.
While developing a maven project SET in eclipse using m2e, you are supposed to import all the projects into your workspace and you should do java development in module1 & module2.
With the current way of editing java source files, you are in detached mode and none of the advanced instruments from JDT is available to you as this java file is not part of a known java model to eclipse.
Try right clicking on your project and do Import... -> Existing Maven Projects. This way you should end up with three projects in your workspace one being the pom project and other two (supposedly both) java projects. Then all java development should be done in project1 and project2. M2e is smart enough to create in-workspace dependencies for the java projects.
Hasan Ceylan