Is it possible to squash or have common resource path for Gradle multi build?
This is my path structure
Root
+--- src
| +--- main
| | +--- resources <- I want this to be common for all my sub projects
+--- Subproject 1
\--- Subproject 2
I found the solution below:
subprojects {
...
sourceSets.main.resources.srcDir "${rootDir}/src/main/resources"
...
}
Related
I have a gradle project that contains 2 subprojects: common & demo.
The common project depends on a published library:
dependencies {
implementation("eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0")
...
The demo project depends on common as part of its API:
dependencies {
api(project(":common")) {
isTransitive =true
}
}
When I compile both, I observe the correct dependency in common:
compileClasspath - Compile classpath for source set 'main'.
+--- org.scala-lang:scala-compiler:2.12.11
| +--- org.scala-lang:scala-library:2.12.11
| +--- org.scala-lang:scala-reflect:2.12.11
| | \--- org.scala-lang:scala-library:2.12.11
| \--- org.scala-lang.modules:scala-xml_2.12:1.0.6
+--- org.scala-lang:scala-library:2.12.11
+--- org.scala-lang:scala-reflect:2.12.11 (*)
\--- eu.timepit:singleton-ops_2.12:0.5.0
+--- org.scala-lang:scala-compiler:2.12.8 -> 2.12.11 (*)
+--- org.scala-lang:scala-library:2.12.8 -> 2.12.11
\--- com.chuusai:shapeless_2.12:2.3.3
+--- org.scala-lang:scala-library:2.12.4 -> 2.12.11
\--- org.typelevel:macro-compat_2.12:1.1.1
\--- org.scala-lang:scala-library:2.12.0 -> 2.12.11
but in demo, the transitive dependecies under common are empty!
compileClasspath - Compile classpath for source set 'main'.
+--- project :common
+--- org.scala-lang:scala-compiler:2.12.11
...
This leads to the very common classpath missing errors, like:
[Error] /xxx/DoubleVectorDemo.scala:9: Symbol 'type shapeless.ProductArgs' is missing from the classpath.
This symbol is required by 'object edu.umontreal.kotlingrad.shapesafe.tensor.DoubleVector'.
Make sure that type ProductArgs is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'DoubleVector.class' was compiled against an incompatible version of shapeless.
So what's the point of dropping libraries for something that is part of your API? And how to override this behaviour in all projects?
From the gradle java-plugin doc,
The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component. Dependencies appearing in the api configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers. Dependencies found in the implementation configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers' compile classpath
Let's say of you want to expose eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0 to all of the common library then you need to add this as api dependency in common module build.gradle.kts.
dependencies {
api("eu.timepit:singleton-ops_${vs.scalaBinaryV}:0.5.0")
$ go version
1.13.3
I have a folder structure as follows:
GOPATH
+---src
+--- my-api-server
+--- my-auth-server
+--- main.go
+--- go.mod
+--- go.sum
+--- my-utils
+--- go.mod
+--- go.sum
+--- uuid
+--- uuid.go
my-auth-server uses my-api-server/my-utils/uuid as a dependency
I tried moving my-utils inside my-auth-server, but as a library, my-utils will be used in multiple places.
Now, my-utils also has a go.mod, but that contains a module declaration.
If I place it in my-auth-server, the module path becomes my-api-server/my-auth-server/my-utils
If I have 2 servers,
my-auth-server
my-session-server
I cannot place my-utils inside both because there can only be one module declaration per go.mod.
So, how I use this in two different projects as submodule?
Any help in solving this would also be appreciated.
A clean way to do achieve this is to have utils a standalone module outside of all projects and then import wherever you want. Since its evident you want it to be a module itself.
Like
GOPATH
+---src
+--- my-api-server
+--- my-auth-server
+--- main.go
+--- go.mod
+--- go.sum
+--- my-utils
+--- go.mod
+--- go.sum
+--- uuid
+--- uuid.go
But if you still need to have utils also maintained as part of your API server then have your API server as module and import it wherever you need utils package. This is discouraged but will not do any harm since GO optimizes as part of compilation required context.
Like this
GOPATH
+---src
+--- my-api-server
+--- my-auth-server
+--- main.go
+--- go.mod
+--- go.sum
+--- my-utils
+--- uuid
+--- uuid.go
What i understand is you need to maintain multi modules in single repo and cross refer. As far as I understand this is not how its supposed to work since you can always cross refer nested package by module relative path.
Also maybe you know this, but since you are using modules, you need to sit in GOPATH/GOROOT for resolution.
I have some projects that depend on others. I also have a project that depends on two projects that each one depends on the same project. Something like this:
-Project A
* Project 1
** Project C
* Project 2
** Project C
And the structure of the workspace is like this:
-ProjectA
-ProjectC
-Project1
-Project2
All the projects are at the same level.
So in the settings.gradle in my Project A I have:
include ':Project1',':Project1:ProjectC',[...]
project(':Project1') = new File('../Project1')
project(':Project2') = new File('../Project2')
project(':Project1:ProjectC') = new File('../ProjectC')
project(':Project2:ProjectC') = new File('../ProjectC')
And in the build.gradle I do:
dependencies{ compile project('Project1'),project('Project2')
The problem is that it is not correctly added to the classpath. I think since both Project1 and Project2 depends on ProjectC it is overwritten somehow. Any ideas?
Thanks.
EDIT
Here is the tree of dependencies:
Root project 'ProjectA'
+--- Project ':ProjectB'
| \--- Project ':ProjectB:Project1'
| +--- Project ':ProjectB:Project1:Project2'
| \--- Project ':ProjectB:Project1:Project3'
\--- Project ':ProjectC'
\--- Project ':ProjectC:Project1'
+--- Project ':ProjectC:Project1:Project2'
\--- Project ':ProjectC:Project1:Project3'
For a workspace that looks like this:
rootFolder
|
|- build.gradle
|- settings.gradle
|
|- ProjectA
| |-build.gradle
|
|- Project1
| |-build.gradle
|
|- Project2
| |-build.gradle
|
|- ProjectC
|-build.gradle
Your settings.gradle should look like this (irrespective of dependency relationships of the sub projects):
include ':ProjectA',':Project1',':Project2',':ProjectC',
You're just telling the root project that there are 4 subprojects and where they are located. That's it.
Now the dependency relationships are handled inside each subproject's build.gradle files. For a dependency relationship that looks like this:
ProjectA
|-Project1
| |-ProjectC
|
|-Project2
|-ProjectC
ProjectA's build.gradle:
dependencies{
compile project(':Project1')
compile project(':Project2')
}
Project1's build.gradle:
dependencies{
compile project(':ProjectC')
}
Project2's build.gradle:
dependencies{
compile project(':ProjectC')
}
What I finally did is change in the classpath the paths that where wrong like this:
build.gradle
eclipse{
classpath{
file{
whenMerged { classpath ->
classpath.entries.find { entry ->
entry.kind == 'src' && entry.path.contains('ProjectC')
}.each{ entry ->
entry.path=file("/ProjectC")
}
}
}
}
}
And it works fine. I still don't know why gradle doesn't make the classpath correctly...
I have a gradle project with several subprojects. and I have defined several dependencies in library with version numbers and aliases in the root project. Now whenever subproject needs it it can define that alias with what level it wants e.g. compile.
root
- build.gradle
- libraries
- xercesImpl: 'xerces:xercesImpl:2.8.1',
- xalan: 'xalan:xalan:2.7.1',
\ project1 : ear
- build.gradle
- ear project('project2')
\ project2 : jar
- build.gradle
- compile libraries.xercesImpl
- compile libraries.xalan
Since I have defined xercesImpl and xalan as dependencies of project1 and project1 is included in project2 ear those jars should be added to EAR, but it's getting excluded from EAR. I checked and transitive dependencies is not declared anywhere as false.
I have printed dependency tree with gradlew and it prints only above 2 jars as excluded others are included:
+--- org.hibernate:hibernate:3.1.3
| +--- commons-logging:commons-logging:1.0.4 -> 1.1
| | +--- log4j:log4j:1.2.12
| | +--- logkit:logkit:1.0.1
| | +--- avalon-framework:avalon-framework:4.1.3
| | \--- javax.servlet:servlet-api:2.3
| +--- ehcache:ehcache:1.1
| | \--- commons-logging:commons-logging:1.0.4 -> 1.1 (*)
| +--- cglib:cglib:2.1_3
| | \--- asm:asm:1.5.3
| +--- asm:asm:1.5.3
| +--- asm:asm-attrs:1.5.3
| +--- commons-collections:commons-collections:2.1.1 -> 3.1
| +--- dom4j:dom4j:1.6.1
| +--- javax.transaction:jta:1.0.1B
| \--- antlr:antlr:2.7.6rc1 -> 2.7.6
+--- net.sf.ehcache:ehcache:2.9.0
| \--- org.slf4j:slf4j-api:1.7.7
+--- xerces:xercesImpl:2.8.1 (*)
+--- xalan:xalan:2.7.1 (*)
I want to find all my Java code dependencies on libraries that I have not included as top level dependencies in Gradle.
My first though as to how to accomplish this is to turn off all transitive dependencies in Gradle and see what compilation errors I get.
From my research the way to do this seems to be:
configurations.all { transitive = false }
Is there a better way, or does this do it?
I'm not sure I understand the question, but the command line "gradle dependencies" might help.
For example, consider this (from this modest project):
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.6.4'
groovy 'com.google.guava:guava-collections:r03'
releaseJars 'org.codehaus.groovy:groovy-all:1.6.4'
releaseJars 'com.google.guava:guava-collections:r03'
}
Using gradle dependencies gives output such as:
compile - Classpath for compiling the main sources.
+--- org.codehaus.groovy:groovy-all:1.6.4
| +--- junit:junit:3.8.2
| +--- org.apache.ant:ant:1.7.1
| | \--- org.apache.ant:ant-launcher:1.7.1
| +--- org.apache.ant:ant-launcher:1.7.1
| \--- jline:jline:0.9.94
| \--- junit:junit:3.8.1 -> 3.8.2
\--- com.google.guava:guava-collections:r03
+--- com.google.guava:guava-annotations:r03
\--- com.google.guava:guava-primitives:r03
....