Syncronize Gradle Projects with workspace failed error in eclipse - java

my application is in java and the IDE used is Eclipse.
I am facing below mentioned issue on refreshing my gradle project.
[Cannot nest
'MyApp-Service/src/test/java/com/mycompany/mymodule/myservice/functional' inside 'MyApp-Service/src/test/java'. To enable the nesting exclude 'com/' from 'MyApp-Service/src/test/java']
here is my folder structure
main folder structure
MyApp-Service/src/main/java/com/mycompany/mymodule/myservice/controller
test folder structure
MyApp-Service/src/test/java/com/mycompany/mymodule/myservice/functional
Below is my build.gradle code snipet
sourceSets {
functionalTest {
java {
srcDir file('src/test/java/com/mycompany/mymodule/myservice/functional')
}
}
}
Most confusing part is if i set the funtionalTest gradle source dir to any other path even if give some junk path the gradle builds fine.
For eg
sourceSets {
functionalTest {
java {
srcDir file('NotAvalidPath')
}
}
}
Please help me to resolve the issue . Thanks in advance.

Related

cant have project structure "src/main/java" in eclipse using Gradle

I used to have a "src/main/java" gradle project structure in eclipse, but after some changes by another person and subsequent pulls from github I lost that project structure and it is now a total mess. Also gradle is not loading any dependency and says "the import ..cannot be resolved"!
How to take control of that?
In the pic I show two diff projects, in the left one with a correct folder structure "src/main/java", in the right the one with issues...pic here
I already tried changes in the build path and it doesn't seem to work.
had the other person updated any information with build.gradle ?
sourceSets {
main {
java { srcDirs = ["src/main/java"] }
resources { srcDir "src/main/resources" }
}
}
I believe this should fix the issue for you , or if you can share your build.gradle file then We can have a look .

IntelliJ IDEA annotation processing doesn't generate sources in configured forlder

I'm struggling with IntelliJ Idea (IntelliJ IDEA 2018.3.2 (Ultimate Edition)), Gradle, and Immutables library. What I'm trying to do is generating sources in the generated directory as expected by the configuration at Using annotation processor in IDE > IntelliJ IDEA.
At the moment the result I get is that both compiled classes and sources are put inside /build/classes/java/main Have you got the same issues? Do you have suggestions to solve the problem? I'm looking for answers but I didn't find a working solution yet.
Yes, by default Gradle puts all generated sources together with compiled ones.
Please configure it like this:
def generatedJavaSourcesPath = "$buildDir/generated-sources/java"
def generatedJavaSourcesDir = file(generatedJavaSourcesPath)
compileJava {
options.compilerArgs = [
// Override the directory where to place generated source files.
"-s",
generatedJavaSourcesPath
]
}
And to add generated sources to the project
sourceSets {
main {
java {
srcDir generatedJavaSourcesDir
}
}
}
Just add it to the build.gradle

How to add JNI sources to my project in Android Studio?

I'm using Android Studio 2.2.3 and I have a nice jniLibs directory created by AS when importing Eclipse project. It took the jar file with .so files and it created a nice structure for every architecture:
I, however, have sources of those libraries and I would like to add them to the structure, so I could edit them and debug easily.
How should I proceed?
The only relevant entry I have in my build.gradle file is:
dependencies {
compile files('libs/sdk.jar')
}
Thank you
I was able to do this by removing the dependencies section and adding:
sourceSets {
main {
jniLibs {
srcDirs = ['jni/db', 'jni/minizip', 'jni/roxml']
}
}
}
Now I can nicely track my source code in Android Studio.

How to add source files to android studio project?

I currently try to get a huge Android Studio Project to compile. My problem is that I depend on java classes in a different git repo. I fixed it by adding the repo as a submodule. I'm an absolute newbie to gradle, so my approach was to add root, where the .java files are located as a a sourceset:
sourceSets {
main.java.srcDirs += '../../ROOT-OF-SOURCE-FILES/'
}
This resolves the dependencies. In "ROOT-OF-SOURCE-FILES" are a bunch of files not needed for my project and this also causes gradle not to build, because there are also no android files.
Next thing I tried is to point to the specific folders I depend on, but then it say "File path does not correspond to package name"
My question is how can I add the classes (including their dependencies) I need or how can I exclude the stuff I don't need (I also tried the exclude with gradle, but that didn't work).
You can use exclude to ignore parts of your source tree, see https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287:
sourceSets {
main {
java {
srcDirs 'main/src'
exclude '**/package2/**'
}
}
}
Another option is to create a symbolic link to the one branch that you really need for Android Studio, e.g.
src/main/
package1
package3
package2
linked/package1 -> src/main/package1
and
sourceSets {
main {
java {
srcDirs 'linked'
}
}
}

gradle: compile android junit test apk file

Can I compile Android JUnit test apk file by using gradle script? Now my test class is:
public class main extends ActivityInstrumentationTestCase2<LoginWindow> {
public main() {
super("com.tecomgroup.handifox", LoginWindow.class);
}
...
}
and gradle says that he cannot find class LoginWindow. Should I add the LoginWindow.java to dependencies {} block? Will such test work? Or may be there is another way to compile test apk file?
When using Gradle Android plugin, you no longer need to have a separate project for testing. Production sources should be put into src/main/java directory, test sources should be in src/instrumentTest/java. The same applies to resources.
From Android Gradle plugin User Guide on project structure.
Project Structure
The basic build files above expect a default folder structure. Gradle follows the concept of convention over configuration, providing sensible default option values when possible.
The basic project starts with two components called “source sets”. The main source code and the test code. These live respectively in:
src/main/
src/instrumentTest/
Inside each of these folders exists folder for each source components.
For both the Java and Android plugin, the location of the Java source code and the Java resources:
java/
resources/
For the Android plugin, extra files and folders specific to Android:
AndroidManifest.xml
res/
assets/
aidl/
rs/
jni/
Note: src/instrumentTest/AndroidManifest.xml is not needed as it is created automatically.
You can change the standard project layout
sourceSets {
instrumentTest {
java {
srcDir '../other/src/java'
}
resources {
srcDir '../other/src/resources'
}
}
}

Categories

Resources