Is it possible to depend on a specific sub project in qmake? - qt-creator

Suppose I have one big project Example with two subprojects, ProjectA and ProjectB. ProjectB, at the same time, has two subprojects, ProjectB1 and ProjectB2. Is it possible to specify that ProjectA depends of one of ProjectB's subprojects?
projectA.pro
TEMPLATE=app
...
projectB.pro
TEMPLATE=subdirs
SUBDIRS+= projectB1 projectB2
projectB1.file = projectB1.pro
projectB2.file = projectB2.pro
Example.pro
TEMPLATE = subdirs
SUBDIRS += projectA projectB
projectA.file = projectA.pro
projectA.depends = projectB.projectB1 (?)
projectB.file = projectB.pro

Can be done by explicitly specifying projectB1. Add this to the end of Example.pro:
projectB1.file = projectB1.pro
projectA.depends = projectB1
SUBDIRS += projectB1

Related

Gradle: Set context root of web application

I have 2 Gradle projects, A is the root, and B is a subproject of A.
Project B generates a .war file, which is included in the .ear file, that project A generates.
I'd like to implement a general solution, where I can change the context root of project B.
Based on my research, I should call the ear.deploymentDescriptors.webModule(path, contextRoot) method, where path is the path of the artifact B in the ear.
How can I get the name of the artifact of B from project A, so that I have something to call the above mentioned method?
Is there a better way to set the context root?
Assume project A has a build.gradle and within ear, the below code can be solve this -
plugins {
id 'ear'
}
dependencies {
deploy project(path:':b', configuration: 'archives')
}
ear{
/* some basis configuration */
libDirName 'APP-INF/lib'
deploymentDescriptor {
/* Some basic attributes */
fileName = "application.xml"
version = "8"
def Set<Project> subProj = project.getSubprojects();
subProj.each{proj ->
if(proj.name.contains("B")){
webModule(proj.name + "-" + proj.version + ".war", "/"+ proj.name)
} //if close
}//each close
}//deploymentDescriptor close
}//ear close

Reading pom version in a pipeline job if pom is not in project root

I have tried using readMavenPom like the following to get the pom version and so for this has been working very well as the pom.xml file has been present in the root of the project directory.
pom = readMavenPom file: 'pom.xml'
For some of our projects, this pom.xml won't be available in the root of the project repository instead it will be available inside the parent module so in that case, we modify the groovy script like the following.
pom = readMavenPom file: 'mtree-master/pom.xml'
There are only two possibilities, either the pom.xml file will present in the root or it will be inside the parent module. So is there a way to rule out this customization that we make every time?
I'd check if the file exists in a specific location with fileExisits:
def pomPath = 'pom.xml'
if (!(fileExists pomPath)) {
pomPath = 'mtree-master/pom.xml'
}
pom = readMavenPom file: pomPath
Bonus: Check multiple paths
def pomPaths = ['pom.xml', 'mtree-master/pom.xml']
def pomPath = ''
for (def path : pomPaths) {
if (fileExists path) {
pomPath = path
break
}
}
// check that pomPath is not empty and carry on

Gradle build jars from multiple folders

I have a folder of unpacked jars like (As i removed the signatures):
folder
- unpackedJar1
- unpackedJar2
- unpackedJar3
Now i want to repackage them again to jars like "unpackedJar1.jar", "unpackedJar2.jar" and so on with a custom manifest. How can I archive that? I can't find a working solution.
You can create Jar tasks with custom manifest dynamically for each folder and then assign them with an aggregate task. For example:
task packAll{
description = 'Pack all data in separated JARs'
}
//list of folders with unpacked data
def unpackedFolders = ['unpackedJar1', 'unpackedJar2', 'unpackedJar3']
//create new Jar task for each folder and make packAll depends on this one
unpackedFolders.each{ folderName ->
def packTask = project.tasks.create(name: 'pack_' + folderName, type: Jar){
archiveName = folderName + ".jar"
from(project.files('folder/' + folderName))
manifest{
attributes(
'source': folderName
)
}
}
project.packAll.dependsOn packTask
}

How to collect jars with sources from projects in dependencies list?

I have a simple multi-project build:
root
|___ a
|___ b
|___ c
build.gradle in root project:
subprojects {
task jarSources(type: Jar, dependsOn: classes) {
classifier = 'source'
from sourceSets.main.java, sourceSets.main.resources
}
}
build.gradle in project a:
dependencies {
compile project(':b')
compile project(':c')
}
task archiveDependencySources(type: Zip) {
...
}
Task archiveDependencySources is intended to collect all jars with sources from projects on which project a depends. Is there a standard way to do this job?
So far I found the solution that looks a bit ugly:
def allJarSourcesTasks = []
for (def dep : configurations.compile.dependencies)
if (dep.hasProperty('dependencyProject'))
allJarSourcesTasks << dep.dependencyProject.tasks['jarSources']
archiveDependencySources.dependsOn allJarSourcesTasks
archiveDependencySources.from allJarSourcesTasks
This might work (not sure about the null argument):
allJarSourcesTasks = configurations.compile.getTaskDependencyFromProjectDependency(true, "jarSources").getDependencies(null)
For dependsOn, .getDependencies(null) could be omitted, but I believe it is needed for from.

gradle use variables in sub project that are defined in child

Root project build.gradle
subprojects{
task setUpEnvironmentDirs()<<{
file("${distDir}").mkdirs()
// FileTree tree = fileTree(dir:'../../../pngcommon/config-tokens', include:"*.properties")
project.tree.each {File currentFile ->
def fileName = "${currentFile.getName().split("\\.")[0]}"
def destinationFile = "${distDir}/${fileName}/"
file("${destinationFile}").mkdirs()
}
}
}
Sub project build.gradle
copyEnvironmentProperties{
FileTree tree = fileTree(dir:'../../../pngcommon/config-tokens', include:"*.properties")
}
setUpEnvironmentDirs{
FileTree tree = fileTree(dir:'../../../pngcommon/config-tokens', include:"*.properties")
}
The file tree that is commented out in the root project is the variable I am attempting to move to the sub project because the directory path will be different in each sub project. I saw a similar post and set mine up similarly, but I keep getting an error.
gradle use variables in parent task that are defined in child
Error:
What went wrong:
A problem occurred evaluating root project 'services'.
Could not find property 'tree' on project ':service'.
You just need to comment in the code that declares the local variable, and use tree.each instead of project.tree.each. The relative paths will be resolved correctly.

Resources