Gradle/libgdx/Eclipse
Following Project Structure:
MainProject
-build.gradle
-settings.gradle
LibraryProject
-build.gradle
-settings.gradle
I can't seem to declare the dependency to the library correctly.
MainProject build.gradle
dependencies {
compile project(':LibraryProject')
}
MainProject settings.gradle
include ':LibraryProject'
project(':LibraryProject').projectDir = new File(settingsDir, '../LibraryProject')
Refreshing dependencies works without error. But I can't access any library classes.
It is not possible (in almost all cases) to reliably include a root project as a subproject of another multi-project build. You should not share subprojects between different Gradle builds.
There are two ways to solve this:
Change the dependency on :LibraryProject to a normal dependency: YourGroup:LibraryProject:1.0-SNAPSHOT. When you make changes to the library project, you first have to manually build the library project, and install it in a (local) repository. Then you can build the main project.
Make the library project an actual subproject of the main project.
What is best depends on the purpose of the library project. Is it a project to be reused by multiple applications? Then use the first approach. If it is specifically for the main project, then a subproject is better.
Related
I'm developing library with Maven system, which is published in the Nexus repository.
In the nexus (and the maven build as well), the project produces the final jar named <projectName>-<version>.jar - this is exactly what I want.
Now, I decided to split the library into maven modules and therefore top level pom.xml have <packaging>pom</packaging>. The build also do not produce final <projectName>-<version>.jar, instead it produces <moduleName>-<version>.jar for each module.
What I want to achieve is to have the project split into modules and be able to produce final <projectName>-<version>.jar containing defined modules. Is this possible?
Is it possible to solve this issue migrating to the Gradle?
When you decided to split the library into multi modules it means that you decided to build them independently. So it's expected that each module creates it's own <moduleName>-<version>.jar.
Now when you use the created modules as dependencies for the bigger module with scope of compile maven would automatically add them to lib of the project.
So in your case you don't need to change packaging to pom and just add the modules as dependency in the pom.xml file and let maven to create the final jar for you.
Also if you want use pom packaging there is a good question here which might help you.
In the past, I've had great success in providing test helpers in a core or common project, and having those classes available to other sub-projects using the following:
Common Project A
task testJar(type: Jar) {
classifier = "tests"
from sourceSets.test.output
}
artifacts { testRuntime testJar }
Dependent Project B
testCompile(project(path: ":project-a", configuration: "testRuntime"))
However, I have the same requirement between two projects that do NOT share a Gradle multi-project hierarchy. To clarify, these are completely separate projects. They are in different repositories, using different build scripts. They are not sub-modules within a parent project.
To futher complex matters, I'm using the Java Library plugin and the Maven plugin to install libraries locally. In other words, I'd love for the second project to include a dependency as such:
testImplementation 'com.mycompany:common-test:1.0.0'
What should the first "common" project look like to a) generate that test jar and b) allow it to be installed to Maven?
Many thanks for all help.
I've found that it's best to put any test utilities in their own separate project rather than building a "test" jar from src/test/java and src/test/resources.
It seems that netflix feel the same as me. Previously they mentioned their test-jar plugin as deprecated in their documentation, now it doesn't even get a mention in the readme
I went through this link to import a gradle project as dependency into another gradle project. Is there a way to include a maven project as dependency into a gradle project?
If that Maven project is built somewhere else and deployed to a Maven repository, you can specify the artifact it produces as a simple compile dependency. If this Maven project is somehow a subproject of a Gradle multi-project build, I suppose you could hack it to work by simply ignoring the Maven POM file and perhaps adding a build.gradle to that project.
To use the solution described on the link that you provided - both projects must be gradle and included in gradle settings. Therefore you can use project closure to compile and depend on the project without building it explicitly.
I am not aware of any way to do this with maven project. I understand you use some maven plugins that you dont want to rewrite in gradle as simply can not find any equivalents etc. Often had that problem.
In this scenario I would suggest to build maven project and depend on a built jar in your gradle project.
Otherwise you could probably amend sourcesets in your gradle project to include maven classes. But I think it would be to complicated.
If I would be you I would turn it into gradle and try to replicate what you had using maven or just build the artifact and depend on it in dependencies closure.
Gradle is not that new anymore and there are many plugins that are superseding old good maven stuff.
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
I want to create, in the same project, so that my IDE allows me to code them all, the following subprojects :
a java package
a gradle plugin that adds a dependency on the java project (artifact)
a gradle sample that uses this plugin
The problem is that the sample, to be evaluated, will need to use the plugin, then the plugin will add the dependency.
BUT, to compile the java package, I need all the subprojects to be evaluated...including the sample. And the sample can't be evaluated as it needs the java dependency...
How can I do ?
I didn't find anyway to get all 3 subprojects in the same project. I tried configuration on demand but the buildScript of the sample still is evaluated. My only work around is to remove the sample subproject from the project.