I am new to gradle so this question may be silly, but i have a project configured with the 'java' plugin like so:
apply plugin: 'java'
and it has a file structure like so:
src
`-- test
|-- java
| `-- com/example/Test.java
`-- resources
`-- com/example/test.txt
When i run gradlew testClasses (or processTestResources more specifically) the Test.class appears in the build folder but the test.txt does not get copied. am I missing something? my understanding is that this should be standard behaviour. do i need to include it in the CopySpec?
I am running gradle 1.10
After a brief look at my build directory for the project, I noticed there is a seperate folder for resources apart from classes. So it is copying there.
from what I understand the resources folder is available on the classpath at runtime, But I was expecting the physical (meta-physically speaking) file to be in the same directory as the Test.class file in my code. hence my question.
Related
I have created a simple maven project with a parent pom and a module pom. When i execute a mvn clean install i notice that the parent and the module are in the same level.
Structure of the project in the local repo:
-parent folder
-module folder
While I expected something like that:
-parent folder
+—-module folder
Is this normal ?
What happened if two modules have the same name in this case ?
Assuming you are talking about the local repo usually located at ~/.m2/repository, yes, that is normal. You have to distinguish between the folder layout within the repository and the folder layout for your development.
As mentioned in this question, the artifacts are always in a folder structure according to their coordinates (groupId, artifactId and version).
groupIdSplitAtDots/artifactId/version
Whether some artifacts are modules of another is completely irrelevant for the directory-layout of the local repository.
If you have e.g. the artifacts com.organisation.topic:artifact-parent:1.2, com.organisation.topic:artifact-module1:1.2 and com.organisation.topic:artifact-module2:1.2, the folder structure will be:
com
|-- organisation
|-- topic
|-- artifact-parent
|-- 1.2
|-- artifact-module1
|-- 1.2
|-- artifact-module2
|-- 1.2
Note, that for development it is usually a good idea to have the parent module in a parent folder, resulting in a layout like this:
artifact-parent
|-- artifact-module1
|-- artifact-module2
As per your second question, identical module names (artifactIds) are not allowed. Regarding the artifactId the docs state:
The identifier for this artifact that is unique within the group given by the group ID.
I am not able to select my testfolder in IntelliJ.
For some reason it wasn't there when I created this project, so I added it manually. After I did that, I went to project structure --> modules, where I marked it as a test.
I am simply not allowed to leave my source directory, when creating a testcase.
See image:
The problem doesn't occure when I create a new project, where the testfolder is set automaticly.
It seems that you have wrong project structure.
It should be as follows:
project-name
|-- pom.xml
|-- src
|-- main
| |-- java
| |-- resources
|-- test
|-- java
|-- resources
And don't mark the test directory as a test source root. You should mark the test/java (subdirectory under the test folder) instead:
I have a project structure like this:
config/
foo/
build.gradle
settings.gradle
bar/
build.gradle
baz/
build.gradle
I want to add the config directory to the classpath in foo/build.gradle so that the subprojects bar and baz can access it. I've tried doing this in foo/build.gradle:
subprojects {
apply plugin: 'java'
dependencies {
runtime files('../config')
}
}
But that results in the following entry in the classpath:
/home/me/project/foo/config
When what I actually want is:
/home/me/project/config
I believe it's because runtime files('../config') is being evaluated in foo/bar/build.gradle instead of foo/build.gradle. So, how can I get the path to foo/? I could just use runtime files('../../config'), but it doesn't feel quite right.
Or maybe I'm going about this the wrong way and there's a better place to put the config files?
One way to get to your current config folder location irrespective of which project/folder level you're at is:
"$rootDir/../config"
I see a lot of examples of Gradle-built Java/Groovy projects that have the following structure:
some-app/
src/
main/
test/
docs/
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle
gradle.properties
gradle/
*.gradle
I understand that build.gradle is the main buildscript and that gradle.properties is its properties file. But settings.gradle really throws me. Inside it I see:
rootProject.name = "someApp"
But this seems like it belongs in gradle.properties. I'm also wondering where the gradlew and gradlew.bat files come from, they seem to be generated.
Finally, I'm wondering why there are so many *.gradle files under the gradle/ dir: are these plugins, or extension scripts of some sort. They are all pulled in from the main build.gradle like so:
apply "gradle/fizz.gradle"
apply "gradle/buzz.gradle"
etc.
So:
What properties are supposed to go in settings.gradle that are not supposed to go in gradle.properties?
How are the gradlew/gradlew.bat files generated?
Why would someone have so many disparate *.gradle files? Why not just 1 big build.gradle buildscript?
1) gradle.properties is normal properties file, while settings.gradle is also a build script. You can add there some code that will be executed during build. Typically this file is needed when You have a multi-module project.
2) When You type gradle tasks in project build directory (empty build.gradle is enough to see it) You'll see wrapper task. This task is used to generate scripts You're asking about. More info.
3) The reason is that all these files have different responsibilities that are cleanly separated.
Is it mandatory to have a directory with same name as project in gradle ? My code is like this:
.
|-- build.gradle
`-- suites
`-- lrgabc.gradle
1 directory, 2 files
content of suites/lrgabc.gradle
$ cat suites/lrgabc.gradle
project(':lrgabc') {
task block1 << {
println "Hello from lrgabc.block1"
}
}
Content of build.gradle
apply from: 'suites/lrgabc.gradle'
When I run, gradle -q :lrgabc:block1 I get
* Where:
Script '/home/skgupta/gradle-examples/multiproject/suites/lrgabc.gradle' line: 1
* What went wrong:
A problem occurred evaluating script.
> Project with path ':lrgabc' could not be found in root project 'multiproject'.
Is it mandatory to have 'lrgabc' as a directory under 'multiproject' ?
What I'm trying is under one single project, create multiple test suites using gradle. Each test suite is one gradle file, where each task in that gradle represent one test [These are non java tests, like perl, python..etc]
How do I solve this ?
Each subproject in a multi-project Gradle build needs to have a separate project directory. However, directory names do not have to correspond to project names (this is configurable in settings.gradle).
You really want to take a look at the documentation for multi-project builds - http://www.gradle.org/docs/current/userguide/multi_project_builds.html There are also samples in Gradle distribution that can help you.
You don't need to create new projects to create more test tasks. You can have these tests in one project. It is quite common to define multiple test suite like unit and functional tests this way. http://blog.safaribooksonline.com/2013/08/22/gradle-test-organization/ shows a possible implementation.