I have the next project structure.
\rootProj
|
+--\moduleA
| |
| +--\build
| |--build.gradle
| ...
|
+--\moduleB
|
+--\main
| |
| +--\resources
| ...
|
|-build.gradle
...
I'm searching an approach to put everything from moduleA\build to moduleB\main\resources.
Could someone help me with this task?
I've googled about it but found nothing - I'm new in Gradle and it may be a cause I can't ask in the right way.
Thanks in advance!
As an answer to my question I've made the next solution:
buildscript{
ext{
generatedResOutDir = file("$buildDir/generated-resources")
}
}
sourceSets {
main{
output.dir(generatedResOutDir, builtBy: 'copyRes')
}
}
task copyRes(type: Copy){
//for to be certain a directory
//we are going to copy from
dependsOn ':moduleA:build'
from project(':moduleA').buildDir
into '${generatedResOutDir}/static'
}
This solution is inspiried by Gradle DSL SourceSetOutput doc.
Related
I am trying read a project property from command line interface. There is a task gradle properties, which prints all of them. Therefore, I can write: gradle properties | grep "rootProject: root project" | awk '{print $NF}' | tr -d "'" and get what I want. The returned result is correct. I would like to use a proper gradle command to achieve the same result. What is a gradle command to get the project name?
this is my build.gradle:
plugins {
id 'java'
}
tasks.register("rootProjectName") {
doLast {
println(rootProject.name)
}
}
build {
println 'hi'
}
Looks like you're just after the rootProject.name property. There is no built-in Gradle task that will give you that property. You can write a simple task that prints that value to the console which will simplify your command.
tasks.register("rootProjectName") {
doLast {
println(rootProject.name)
}
}
Then simply call that task with -q:
$ ./gradlew rootProjectName -q
demo
You can see demo is simply printed out for this example.
So far the closest I got is the following build.gradle:
plugins {
id 'java'
}
task printRootProjectName {
doLast {
println('root project: ' + rootProject.name)
}
}
build {
println 'unwanted output'
}
and then:
gradle printRootProjectName -q | grep "root project:" | awk '{print $NF}' | head -n 1
I've the following gradle project structure:
SUPER/
|______A/
| |______A1/
| | |______build.gradle
| |______A2/
| | |______build.gradle
| |______build.gradle
| |______settings.gradle
|
|______B/
| |______build.gradle
| |______settings.gradle
|
|______build.gradle
|______settings.gradle
My build.gradle from the A-Project contains somethings like that:
...
project(":A1") {
apply plugin: "java-library"
dependencies {
api project(":A2")
}
}
project(":A2") {
apply plugin: "java-library"
dependencies {
...
}
}
...
My "Super"-settings.gradle file contains something like that:
rootProject.name = 'SUPER'
include 'A'
include 'B'
In my sub-project "A" the settings.gradle looks like that:
include 'A1', 'A2'
When calling the gradlewrapper like that "./gradlew SUPER:A1:sometask" on the command line from the SUPER-folder, it fails with the message:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\<somepath>\SUPER\A\build.gradle' line: 44
* What went wrong:
A problem occurred evaluating project ':A'.
> Project with path ':A1' could not be found in project ':A'.
But when doing something like that "./gradlew A1:sometask" from the A-sub-project-folder, it works successfully.
can you explain me what am I'm doing here wrong?
I have a Gradle project that I want to import to Versioneye to check if my dependencies are up to date, but it's a complex config file (with external variables etc.) and Versioneye does not manage to handle the dependencies properly.
I don't want to install the Versioneye gradle plugin.
How can I export the dependencies from my repo to Versioneye?
You can list all the dependencies gradle app:dependencies.
With a bit of string manipulation, you can export a "clean" dependencies file and manually upload it to Versioneye.
#!/bin/bash
OUT_DIR='versioneye'
OUT_FILE="${OUT_DIR}/build.gradle"
mkdir -p "${OUT_DIR}"
touch "${OUT_FILE}"
# copy your maven repositories closure below from build.gradle
tee "${OUT_FILE}" <<EOF >/dev/null
allprojects {
repositories {
maven {
url 'https://maven.google.com/maven-google-remote'
}
maven {
url "https://jitpack.io"
}
}
}
EOF
echo 'dependencies {' >> "${OUT_FILE}"
./gradlew app:dependencies | grep '^+---' | sed 's|+--- |compile "|' | sed 's| (\*)||g' | sed 's|$|"|' | sort -u >> "${OUT_FILE}"
echo '}' >> "${OUT_FILE}"
cat "${OUT_FILE}"
cd "${OUT_DIR}"
start .
cd -
echo 'Now, open versioneye.com and manually upload the genreated build.gradle file.'
This will generate a file that looks like this:
allprojects {
repositories {
maven {
url 'https://maven.google.com/maven-google-remote'
}
maven {
url "https://jitpack.io"
}
...
}
}
dependencies {
compile "com.android.support.test.espresso:espresso-contrib:2.2.2"
compile "com.android.support.test.espresso:espresso-core:2.2.2"
compile "com.android.support.test.espresso:espresso-intents:2.2.2"
compile "com.facebook.android:facebook-android-sdk:4.17.0"
compile "com.facebook.fresco:fresco:1.5.0"
compile "com.facebook.fresco:imagepipeline-okhttp3:1.5.0"
...
}
This file can be imported to Versioneye with a file upload and will be processed correctly.
I'm starting to implement a simple component based on angular 2 , but i get an issue tsconfig.json and import
Here is my structure
Root
|
node_modules
| |
| #angular
| |
| Core
| platform-broswer-dynamic
Script
|
Components
|
MyFirstComponent.ts
MyFirstComponentService.ts
Here is my code
import { bootstrap } from '#angular/platform-browser-dynamic'; // this line is ok
import { Component } from '#angular/core'; // this line is ok
import { FirstService } from 'Root/Script/Components/MyFirstComponentService'; // this line get error
#Component({
selector: 'firstcomponent',
template: '<div>My First Component</div>',
})
export class MyFirstComponent {
constructor(public abc : FirstService)
{
console.log(abc.doSomething());
}
}
bootstrap(MyFirstComponent, [FirstService]);
But i get error at
import { ABCService } from 'Root/Script/Components/MyFirstComponent';
Because some reason i don't want to use import { ABCService } from ./MyFirstComponent';
What config should i use in tsconfig.json to make three import work ? i've tried with rootDir but it not help
I'm using VS2015 , typescript 1.8.32
Thanks you very much!
You do not need to specify the full path, the service and the component are both in the same file location so you will need to use ./ like so:
import { FirstService } from './MyFirstComponentService';
EDIT: Going by your comment, I THINK you're asking this. Say you have another sub folder inside your Root, and another sub folder inside your Components, so you have this now:
Root
|
node_modules
| |
| #angular
| |
| Core
| platform-broswer-dynamic
Script
|
Components
| |
| MyFirstComponent.ts
| MyFirstComponentService.ts
| |
| navbar
| |
| navbar.component.ts
| navbar.component.html
|
Shared
|
authservice.component.ts
if you wanted to access the the navbar.component from inside that same file, you would use:
import { FirstService } from './navbar/navbar.component';
You would would need to specify that from the current folder, ./, go to the navbar folder, then get the component there.
Now if you wanted to access the authservice.component, you would do the following:
import { FirstService } from '../Shared/authservice.component';
The reason for this is that the Shared folder is located one folder higher than the current folder you're in, that's why you would use ../, this essentially takes you one folder "higher".
Does that explain it better? I just added random "common" components. Also maybe consider changing your folder structure, and naming your folder/components as lower case only.
use ./MyFirstComponent in place of that full path.. it work fine with that
I know that Gradle has the excellent dependencies task that lists out all dependencies for a project. However, it returns them in a tree listing.
I would like to get a list of all my dependencies as they are resolved in just a flat list. Similar to how the Maven dependency plugin list goal behaves.
Here is a short task that meets that need:
task('dependenciesList') << {
println "Compile dependencies"
def selectedDeps = project.configurations.compile.incoming.resolutionResult.allDependencies.collect { dep ->
"${dep.selected}"
}
selectedDeps.unique().sort().each { println it}
}
The third line is the interesting part. You need to get the configuration you care about (compile) then instead of getting dependencies there, the incoming.resolutionResult will provide the resolved values and versions.
<< was removed in Gradle 5. To make the task work in Gradle 5 and later versions, remove << and use doLast { } instead. Also, use runtimeClasspath or compileClasspath for the configuration instead of compile:
task('dependenciesList') {
doLast {
println "Compile dependencies"
def selectedDeps = project.configurations.compileClasspath.incoming.resolutionResult.allDependencies.collect { dep ->
"${dep.selected}"
}
selectedDeps.unique().sort().each { println it}
}
}
Without modifying the build, flatten the tree using sed, sort, and uniq as follows:
$ gradle dependencies | sed 's/^.* //' | sort | uniq
Alternatively, with slightly tighter sed matching:
./gradlew dependencies \
| sed -n 's/.*--- \([^ ]*\).*/\1/p' \
| grep -v "^project$" \
| sort \
| uniq
Thanks for the answers already supplied.
Finally I complete it by a more standard way:
project.gradle.addListener(new DependencyResolutionListener() {
#Override
void beforeResolve(ResolvableDependencies dependencies) {}
#Override
void afterResolve(ResolvableDependencies dependencies) {
dependencies.resolutionResult.allComponents.each { select ->
println "selected component: ${select} " + select.selectionReason
}
}
})
Project implementation will also be resolved in this way, and the final selected component version will be resolved correctly.