Gradle include project on different parent - intellij-idea

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')

Related

How configure a gradle multi-module project?

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")

How to use a JAR file in IntelliJ after downloading?

I want to use the import javax.ide in IntelliJ, specifically exploring MetaClass and seeing what it can do. I've downloaded the JAR (198) from https://download.oracle.com/otndocs/jcp/standard_extension_ide-1.0-fr-oth-JSpec/, and I know I'm supposed to somehow add it to dependencies under Project Settings -> Modules -> Dependencies, but I'm not sure what exactly I'm supposed to add from the downloaded folder. The folder containing javax/ide itself is somewhat buried, but I tried adding different levels of directories and none of them worked. The actual folder doesn't even contain java files, it contains a bunch of htmls so I might just be downloading the wrong thing. Thanks for the consideration
I've downloaded the JAR (198) from
It is not a JAR. This is a .zip archive and it does not contain compiled classes in a form of a JAR. It has only source files.
If you are working with a JAR - you need to add such a jar file which contains the needed for your classes into the module's dependencies.
If you do not have the JAR but only have sources - you can create a separate module from these sources and then use it as a module dependency to the module where you want to use these classes.

Are project included through gradle safe?

Let's say I want to include a project in my app using gradle. For instance,
I include
compile 'something'
in my build.gradle file
Can I be assured it's safe to include it in my project without going
through the project files?

Using Gradle to Build an IntelliJ Module From Command Line

I understand the basic functionality of gradle, but I don't understand how to use a build.gradle file other than the one in the project's root. I have a project which contains a gradle wrapper in it's root, and a module which has it's own build.gradle file. How do I specify for gradlew to use the module's build.gradle file instead of the one in the root directory?
Specifically, I have an IntelliJ project I have uploaded to my CI server, and I am trying to setup a script to run the builds automatically.
Cheers
It looks like you have a multi-module build which only has a single module... correct?
You could include a settings.gradle which points to the module
You could declare a GradleBuild task in the root module to invoke the sub module.
A good place to look for inspiration is the java samples and the organizing build logic page in the documentation. An impressive feature of gradle is that all of the code snippets which appear in the documentation is sourced from the samples directory which is run as part of their CI build.
Happy Gradling!

How to link source from outside of maven project?

In Maven, is it possible to link additional dependent java src from outside the project folders, so that when we build our main package, maven may include such classes into final jar?
just as we can link any source folder to our project in Eclipse and eclipse treats it as regular project source?
In Maven, is it possible to link additional dependent java src from outside the project folders
Technically, it's possible to add source folders to a build and this is usually done using the build-helper-maven-plugin. However, I would recommend against doing so for directories outside a given module, a maven module should be self contained.