I would like to set up a project with the following structure:
Project 1
+ build.gradle
+ settings.gradle
+ module A
+ build.gradle
+ src
+ ...
+ module B
+ build.gradle
+ src
+ ...
Project 2
+ build.gradle
+ settings.gradle
+ module C
+ build.gradle
+ src
+ ...
+ module D
+ build.gradle
+ src
+ ...
I would like Project 1's module A to depend on Project 2's module D. I would like this to be a source (not maven artifact) dependency and to work with gradle 2.14 and Android Studio 2.1.
I do not control the layout of Project 2 or it's root build.gradle. All I can do is pull it into my workspace and use it.
I have complete control over Project 1, and can set it up any way that I want. I would prefer that a full build of Project 1 did not cause a complete build of Project 2, just :project2:moduleD. Anything that works, though, will do.
I'd like to know how to set up the build.gradle files for Project 1, and what to put in the dependency clause in the build.gradle for Module A.
I'm taking a guess that what you described is not set up a multi-project, that is they are two stand alone projects. If you can't convince the maintainer to publish the artifact anywhere and you always need the latest version of Project 2. Your best bet is to link to the project's output jar file.
compile files('path/to/Project2/build/output.jar')
This would require a build to be run on Project 2 after the latest source is pulled onto the system. If you have a specific location of the project you could automate this a bit more but all of it is pretty fragile.
have you tried a symlink? Make a symlink in project 1 to project D's folder and add it to project 1's settings.gradle
you can check blow URl
https://docs.gradle.org/current/userguide/declaring_dependencies_between_subprojects.html
and make sure that all this project share same root project
Example for gradle:
rootProject.name = 'sof-portofolio'
include 'core:model1','service:model2'
Related
I have a 3 microservices and now i need to create a docker-compose for all of it. So when i trying to fellow all my microservices in one project i get this issue
Project directory 'C:\Users\Dany\IdeaProjects\target-root\target-discovery\app' is not part of the build defined by settings file 'C:\Users\Dany\IdeaProjects\target-root\settings.gradle.kts'. If this is an unrelated build, it must have its own settings file.
What i have to read for fix it?
setting.gradle.kts
project structure
The include in settings.gradle.kts should look like:
include(
":target-discovery"
)
in case there are more sub-folders (e.g. target-discovery/app, target-discovery/app2):
include(
":target-discovery:app",
":target-discovery:app2"
)
When defining a module it should always start with : and sub-folders should be delimited by :
Also make sure your root build.gradle.kts define all relevant plugins or define them in each sub-module. You can also create conventions (https://docs.gradle.org/current/samples/sample_convention_plugins.html)
If you just define plugins in the root it wont affect your sub-projects, one way to achive it (altough i prefer convention plugins) is:
build.gradle.kts
plugins {
kotlin("jvm") version ...
}
subprojects {
apply(plugin = "kotlin")
}
As Tom said, what you need to include isn't target-discovery but target-discovery/app
However, projects included in settings.gradle (or settings.gradle.kts) don't start with the colon symbol, so you should have:
settings.gradle.kts
rootProject.name = "target-root"
include("target-discovery:app")
I have multi module maven project in intelliJ 2019.3 (Ultimate)
I am not able to get all dependencies after several tries. I tried below solutions as well
Solution 1
Solution 2
I noticed under the Maven tool same module shows twice as below
Not sure that caused the issue here.
Strangely I don't see any red lines in the any of the POMs
Provided that you can build project from command line Maven and dependencies are downloaded.
In IntelliJ IDEA please try: File | New | Project from Existing Sources action and point to pom.xml file to import project from. Then choose to delete existing project configuration.
I create a simple sample Spring MVC project, where IntelliJ 14 by default generate a pom with
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
I change it to
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
</properties>
and choose Maven -> Reimport, I can see the dependencies are downloaded to my local .m2 folder
However, when I expend lib folder, all dependencies stays with previous version:
How can I get the latest dependencies showing in \lib folder? I tried to synchronize current project, but it doesn't help this matter
UPDATE
here is my maven setting
UPDATE 2
I forget some detail, which is I create a Spring MVC project in the beginning(so I think it may not be a maven project at the moment), then I right click pom.xml and set current project to maven project.
So I think the jar files listed in \lib folder may be downloaeded via intellij for Spring MVC application, however when I set current project to maven project, it does not remove or update the jar file under the \lib folder.
You should do:
1. Choose menu File \ Project Settings..., In section Build, Execution, Deployment \ Build Tools \ Maven \ Importing, check Import Maven projects automatically. It means IntelliJ IDEA will Synchronize Maven project model and IDEA project model each time when pom.xml is changed.
2. Try closing project, restart IntelliJ IDEA, then reopen the project.
3. Check your internet connection.
IntelliJ isn't shouldn't be looking there for your Maven project dependencies. It is should be using the libraries and resources in your .m2 directory instead.
Mind you, I've left those comments struck out on purpose; depending on your configuration, you may accidentally be doing that.
This is a picture of what the Dozer project looks like. It's a Maven project which I cloned a ways back to see how it worked.
You're going to have to check your Project Structure (Ctrl + Alt + Shift + S) to ensure that the libraries that are coming through are prefixed with "Maven:".
If they are, then the files in your lib folder aren't being used by your project.
In all actuality, those are your global libraries (which you can also find under Project Structure > Global Libraries). Any project has access to them.
If that's causing a conflict, consider deleting those JARs from your global libraries. If you need them for another project, consider adding it to the project's local libraries instead.
Example structure:
messages/
settings.gradle
build.gradle
consumer/
build.gradle
producer/
build.gradle
library/
build.gradle
test/
settings.gradle
build.gradle
library/
build.gradle
The library folders are the same on different projects. However I develop/test the library on a real "messages" projects and then distribute only library in open source.
I want to keep the two projects separate but "link" the library. I tried with a Mac folder alias (naive) which didn't work. Copy pasting the folder is not a great solution. Anyway to link those two?
e.g. have in messages/settings.gradle a path to the other library?
Yes, you could "relocate" the project in your settings.gradle.
def libraryProject = findProject(':library')
libraryProject.projectDir = file('/path/to/other/project')
Is there any way I can copy one pom.xml dependencies into other pom.xml
Update: Well, I have project A and Project B.
Project B is using some dependencies ( like Junit.jar, commons-httpclient, commons-collections, struts)
In the Project A : I would like to copy all project B dependencies in some out folder
This I can specify manually all dependencies jars of Project B in Project A but I would like to do automatically some script in Project A pom.xml.
Note: I don't want to build the project B in Project A pom.xml , I am building Project B separately
Does this make any sense?
If I understand well what you mean, keep only the dependencies in project B pom.xml. If you need something else in this pom, create another directory level B1, and push every other elements in it. Then makes B pom.xml a pom packaging with one module:B1.
Then you can make project B pom.xml the parent of project A pom.xml. A will inherit dependencies from B.
While I understand the spirit of the question (and only the spirit), the relation between project A and project B is still unclear so I'm not sure of the best way to implement this. Here are the options.
First solution: leverage transitive dependencies. There are some rules about them, but basically, if you declare a dependency on Project B in Project A, you'll get some of its dependencies transitively.
Second solution: use inheritance.
Third option: use another project of type pom to group the dependencies and declare a dependency on this pom.
I think the maven invoker plugin does pretty much exactly what you need:
http://maven.apache.org/plugins/maven-invoker-plugin/install-mojo.html
Or create a java class using the maven API, programmatically build a maven project and export the dependencies
start here:
http://maven.apache.org/ref/2.2.1/maven-project/apidocs
read a model:
http://maven.apache.org/ref/2.0.11/maven-model/apidocs/org/apache/maven/model/io/xpp3/MavenXpp3Reader.html
construct a MavenProject object using the model:
http://maven.apache.org/ref/2.2.1/maven-project/apidocs/org/apache/maven/project/MavenProject.html#MavenProject(org.apache.maven.model.Model%29
resolve and export the dependencies
Sean