I am working on gradle script where I am trying to complie the c++ code and my structure are as below.i am trying to compile my code on below machine and it is showing the c++ compiler failed whereas I am not getting an issue with maven can somel
Linux 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
└───src
└───main
├───c++
│ ├───headers (headres is having **.h files)
│ └───native (native contains **.cpp files)
└───resources
└───DSresources
└───DSLib
apply plugin: 'cpp'
//-- set the group for publishing
group = 'com.rohit.singh'
/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.engineBuildVersion
println "${version}"
//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.engineBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"
model {
components {
main(NativeExecutableSpec) {
targetPlatform "x86"
targetPlatform "x64"
sources {
cpp {
source {
srcDir "src/main/c++/native"
}
}
}
}
}
}
Below is the maven code snippet
profile>
<id>Linux</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<packaging.type>so</packaging.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-8</version>
<extensions>true</extensions>
<configuration>
<javahOS>linux</javahOS>
<compilerProvider>generic-classic</compilerProvider>
<compilerExecutable>g++</compilerExecutable>
<linkerExecutable>g++</linkerExecutable>
<sources>
<source>
<directory>NativeJNI/../src/main/c++/native</directory>
<fileNames>
<fileName>JniSupport.cpp</fileName>
<fileName>DiseaseStagingJni.cpp</fileName>
</fileNames>
</source>
</sources>
<compilerStartOptions>
<compilerStartOption>-fPIC</compilerStartOption>
</compilerStartOptions>
<linkerFinalName>NativeJNI</linkerFinalName>
<linkerStartOptions>
<linkerStartOption>-shared -L${basedir}/src/main/resources/DSresources/DSLib -lds64 -Wl,-rpath,${basedir}/src/main/resources/DSresources/DSLib</linkerStartOption>
</linkerStartOptions>
</configuration>
<executions>
<execution>
<id>javah</id>
<phase>generate-sources</phase>
<configuration>
<finalName>LinuxNativeJNI</finalName>
<javahOS>linux</javahOS>
<javahProvider>default</javahProvider>
<javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
<workingDirectory>${basedir}</workingDirectory>
<javahOutputFileName>DiseaseStagingJniWrapper.h</javahOutputFileName>
<javahClassNames>
<javahClassName>com.truvenwealth.analyticsengine.common.diseasestaging.DiseaseStagingJniWrapper</javahClassName>
</javahClassNames>
</configuration>
<goals>
<goal>javah</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
I used the Javah function in below manner.
apply plugin: 'cpp'
apply plugin: 'java'
//-- set the group for publishing
group = 'com.rohit.singh'
/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.ncdefBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.anal
println "${version}"
//name is set in the settings.gradle file
group = "com.rohit.singh"
version = buildProperties.anal
println "Building ${project.group}:${project.name}:${project.version}"
repositories {
maven {
url "http://xxx.tsh.xxon.com:x/factory/libslocal"
}
maven {
url "http://xxx.tsh.xxon.com:x/factory/libs-release"
}
}
dependencies {
compile ([
"com.rohit.singh:engine-common:4.+"
])
}
model {
repositories {
libs(PrebuiltLibraries) {
jdk {
headers.srcDirs "${System.properties['java.home']}/../include",
"${System.properties['java.home']}/../include/win32",
"${System.properties['java.home']}/../include/darwin",
"${System.properties['java.home']}/../include/linux"
}
}
}
}
model {
platforms {
x64 { architecture "x86_64" }
x86 { architecture "x86" }
}
}
model {
components {
main(NativeLibrarySpec) {
sources {
cpp {
source {
lib library: 'main', linkage: 'static'
lib library: 'jdk', linkage: 'api'
srcDir "src/main/c++/native"
include "**/JniSupport.cpp"
include "**/DiseaseStagingJni.cpp"
}
}
}
}
}
}
def nativeHeadersDir = file("$buildDir/nativeHeaders")
//def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(";")
binaries.all {
// Define toolchain-specific compiler and linker options
if (toolChain in Gcc) {
cppCompiler.args "-I${nativeHeadersDir}"
cppCompiler.args "-g"
linker.args '-Xlinker', '-shared -LNativeJNI/src/main/resources/DSresources/DSLib -lds64 -Wl'
}
}
**//def nativeHeadersDir = file("$buildDir/nativeHeaders")
task nativeHeaders {
// def nativeHeadersDir = file("$buildDir/nativeHeaders")
def outputFile = file("$nativeHeadersDir/DiseaseStagingJniWrapper.h")
def classes = [
'com.abcedefgh.nice.common.diseasestaging.DiseaseStagingJniWrapper'
]
inputs.files sourceSets.main.output
inputs.property('classes', classes)
outputs.file outputFile
doLast {
outputFile.parentFile.mkdirs()
def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(":")
println "Using Compile Path: ${compilePath}"
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-o', outputFile
args '-classpath', compilePath
args classes
}
}
}
tasks.withType(CppCompile) { task ->
task.dependsOn nativeHeaders
}**
//def filechange = file("NativeJNI-${project.version}.so")
//println filechange
task fixartifactname (type: Copy) {
//def filechange = "NativeJNI-${project.version}.so"
//println filechange
from 'build/binaries/mainSharedLibrary'
into 'build/libs'
def filechange = file("NativeJNI-${project.version}.so")
println filechange
include('libmain.so')
rename ('libmain.so', '${filechange}')
}
//println fixartifactname
build.dependsOn fixartifactname
Related
I'm trying to set up jacoco for an android project, but there are two issues with the generated report.
1- I declared the destination folder for HTML and XML report but the generated report appears in build/reports/coverage/androidTest/debug
2- the generated report is incorrect and shows that the adder class is not covered, which is wrong.
adder class
class Adder {
fun adder(a:Int,b:Int):Int{
return a+b
}
fun subtractor(a:Int,b:Int):Int{
return a-b
}
}
test class
class AdderTest {
#Test
fun `test`(){
assertEquals(3,Adder().adder(1,2))
}
#Test
fun `substract`(){
assertEquals(-1,Adder().subtractor(1,2))
}
}
jacoco script
apply plugin: 'jacoco'
project.afterEvaluate { project ->
setupAndroidReporting()
}
def setupAndroidReporting() {
tasks.withType(Test) {
// Whether or not classes without source location should be instrumented
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type ->
type.name
}
def productFlavors = android.productFlavors.collect { flavor ->
flavor.name
}
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add('')
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def sourceName, sourcePath
if (!productFlavorName) {
sourceName = sourcePath = "${buildTypeName}"
} else {
sourceName = "${productFlavorName}${buildTypeName.capitalize()}"
sourcePath = "${productFlavorName}/${buildTypeName}"
}
def testTaskName = "test${sourceName.capitalize()}UnitTest"
System.out.println("Task -> $testTaskName")
// Create coverage task of form 'testFlavorTypeCoverage' depending on 'testFlavorTypeUnitTest'
task "${testTaskName}Coverage1"(type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports on the ${sourceName.capitalize()} build."
if (buildTypeName == 'debug') {
reports {
csv.enabled true // change if needed
xml.enabled false // change if needed
xml.setDestination(new File("${project.rootDir.path}/coverage-report"))
html {
enabled true
destination new File("${project.rootDir.path}/coverage-report")
}
}
def fileFilter = [
]
def javaTree = fileTree(dir: "${project.buildDir}/intermediates/javac/$sourceName/classes", excludes: fileFilter)
def kotlinTree = fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/$sourceName", excludes: fileFilter)
classDirectories.from = files([javaTree], [kotlinTree])
executionData.from = files("${project.buildDir}/jacoco/${testTaskName}.exec")
def coverageSourceDirs = ["src/main/java",
"src/$productFlavorName/java",
"src/$buildTypeName/java"]
sourceDirectories.setFrom(files(coverageSourceDirs))
additionalSourceDirs.setFrom(files(coverageSourceDirs))
println "xml report: file://${reports.xml.destination}"
println "html report: file://${reports.html.destination}/index.html"
}
}
}
}
}
android {
buildTypes {
debug {
testCoverageEnabled true
}
}
}
report
I have a Java+Kotlin application, building with Gradle.
Some of its low-level functionality is provided by a separate C++ application.
The two applications communicate via a socket or pipe, using Protocol Buffers and gRPC.
Initially, I'd hoped to build all three (ProtoBuf generated code, Java application, C++ application) in one project, however the cpp-application and java conflict over certain tasks (compile/implementation/test?).
I've since split this into three projects:
/
build.gradle
settings.gradle
cpp-app/
build.gradle
settings.gradle
...
java-app/
build.gradle
settings.gradle
...
protocol/
build.gradle
settings.gradle
build/generated/source/proto/main/java/... <-- Java generated code
build/generated/source/proto/main/cpp/... <-- C++ generated code
...
I have the protocol project successfully generating C++ and Java implementations.
How do I get the C++ and Java application projects to resolve and to use these outputs in their builds?
I solved this while I was writing the question.
The gradle configuration files are shown below. There are a couple redundant blocks which are not needed for this example (or needed at all), however they achieve the objective.
/build.gradle
subprojects {
group = 'com.whatever.your.group'
version = '0.0.0'
repositories {
mavenCentral()
}
}
/settings.gradle
rootProject.name = 'my-project'
include 'java-app'
include 'cpp-app'
include 'protocol'
/java-app/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
plugins {
// Java
id 'maven'
id 'idea'
id 'application'
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.20'
// ProtoBuf
id 'com.google.protobuf' version '0.8.8'
}
description = """"""
sourceCompatibility = 8
targetCompatibility = 8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
mainClassName = 'my.main.Class'
dependencies {
protobuf project(':protocol') // <-- name of protobuf project
compile project(':protocol') // <-- name of protobuf project
// We have "protobuf" and "compile", as "compile" brings in transitive dependencies
testCompile 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.20"
testImplementation "org.jetbrains.kotlin:kotlin-test:1.3.20"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.3.20"
}
sourceSets {
main {
java {
srcDir "src/main/java"
}
kotlin {
srcDir "src/main/kotlin"
}
}
}
/java-app/settings.gradle
rootProject.name = 'java-app'
/cpp-app/build.gradle
plugins {
id 'maven'
id 'cpp'
}
description = """"""
project.tasks.build.dependsOn 'protocol' // <-- name of protobuf project
model {
components {
main(NativeExecutableSpec) {
...
}
}
...
}
/cpp-app/settings.gradle
rootProject.name = 'cpp-app'
/protocol/build.gradle
plugins {
id 'maven'
id 'java'
id 'com.google.protobuf' version '0.8.8'
}
repositories {
mavenCentral()
}
description = """"""
sourceCompatibility = 8
targetCompatibility = 8
dependencies {
compile 'com.google.protobuf:protobuf-java:3.7.0'
compile 'io.grpc:grpc-stub:1.19.0'
compile 'io.grpc:grpc-protobuf:1.19.0'
}
sourceSets {
main {
proto {
srcDir "src/main/proto"
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.7.0"
}
plugins {
grpc_java {
artifact = 'io.grpc:protoc-gen-grpc-java:1.19.0'
}
grpc_cpp {
path = getPluginPath('cpp')
}
grpc_python {
path = getPluginPath('python')
}
}
generateProtoTasks {
generatedFilesBaseDir = "${buildDir}/build/generated/src"
all()*.builtins {
java { }
cpp { }
python { }
}
all()*.plugins {
grpc_java {
outputSubDir = 'java'
}
grpc_cpp {
outputSubDir = 'cpp'
}
grpc_python {
outputSubDir = 'python'
}
}
}
}
clean {
delete protobuf.generatedFilesBaseDir
}
// Used to find executables for generating C++ and Java gRPC
static def getPluginPath(name) {
def path = "which grpc_${name}_plugin".execute()
path.waitFor()
path = path.in.text.trim()
if (!path) {
println "Failed to locate GRPC plugin for ${name}"
} else {
println "Found GRPC plugin for ${name} at ${path}"
}
return path
}
/protocol/settings.gradle
rootProject.name = 'protocol'
Then in the project root, I can run gradle assemble, and:
$ gradle assemble
> Configure project :protocol
Found GRPC plugin for cpp at /usr/bin/grpc_cpp_plugin
Found GRPC plugin for python at /usr/bin/grpc_python_plugin
> Task :cpp-app:linkMainExecutable NO-SOURCE
> Task :cpp-app:mainExecutable UP-TO-DATE
> Task :cpp-app:assemble UP-TO-DATE
> Task :protocol:extractIncludeProto
> Task :protocol:extractProto
> Task :protocol:generateProto
> Task :protocol:compileJava
> Task :protocol:processResources
> Task :protocol:classes
> Task :protocol:jar
> Task :protocol:assemble
> Task :java-app:extractIncludeProto
> Task :java-app:extractProto
> Task :java-app:generateProto
> Task :java-app:compileKotlin
> Task :java-app:compileJava
> Task :java-app:processResources
> Task :java-app:classes
> Task :java-app:inspectClassesForKotlinIC
> Task :java-app:jar
> Task :java-app:startScripts
> Task :java-app:distTar
> Task :java-app:distZip
> Task :java-app:assemble
BUILD SUCCESSFUL in 10s
17 actionable tasks: 17 executed
I'm trying to setup a C++ project that itself uses another (not gradle) C++ project.
Since the compilation doesn't require anything special I tried including the project as a submodule and compiling that library as a library through gradle itself.
To my knowledge I have set up the build script correctly like this:
// Project-Type
apply plugin: "cpp"
// IDEs
apply plugin: "visual-studio"
model {
visualStudio {
solutions.all {
solutionFile.location = "vs/${name}.sln"
solutionFile.withContent { TextProvider content ->
content.asBuilder().insert(0, "# GENERATED FILE: DO NOT EDIT\n")
content.text = content.text.replaceAll("HideSolutionNode = FALSE", "HideSolutionNode = TRUE")
}
}
}
repositories {
libs(PrebuiltLibraries) {
easyloggingpp {
headers.srcDir "lib/easyloggingpp/src"
}
eigen {
headers.srcDir "lib/OpenNN/eigen/src"
}
}
}
platforms {
x86 {
architecture "x86"
}
x64 {
architecture "x64"
}
}
buildTypes {
debug
release
}
components {
tinyxml2(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs "lib/OpenNN"
include "tinyxml2/**/*.cpp"
}
exportedHeaders {
srcDirs "lib/OpenNN"
include "tinyxml2/**/*.h"
}
}
}
openNN(NativeLibrarySpec) {
sources.cpp {
source {
srcDirs "lib/OpenNN"
include "opennn/**/*.cpp"
}
exportedHeaders {
srcDirs "lib/OpenNN"
include "opennn/**/*.h"
}
lib library: "eigen", linkage: "api"
lib library: "tinyxml2", linkage: "static"
}
}
anni(NativeExecutableSpec) {
if(System.properties['sun.arch.data.model'] == "64") {
targetPlatform "x64"
} else {
targetPlatform "x86"
}
sources.cpp {
source {
srcDirs "src"
include "**/*.cpp"
}
exportedHeaders {
srcDirs "src"
include "**/*.hpp"
}
lib library: "easyloggingpp", linkage: "api"
lib library: "openNN", linkage: "static"
}
}
}
binaries {
withType(NativeExecutableBinarySpec) {
if (toolChain in Gcc) {
cppCompiler.args "-Wall", "-Wextra", "-Wpedantic", "-fPIC"
}
if (toolChain in Clang) {
cppCompiler.args "-Weverything", "-pedantic"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/W4", "/FS", "/EHsc"
}
}
withType(SharedLibraryBinary) {
buildable = false
}
withType(StaticLibraryBinarySpec) {
if (toolChain in Gcc) {
cppCompiler.args "-Werror"
}
if (toolChain in Clang) {
cppCompiler.args "-Werror"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/W0", "/EHsc"
}
}
all {
if(buildType == buildTypes.debug) {
cppCompiler.define "__DEBUG__"
if (toolChain in Gcc) {
cppCompiler.args "-Og", "-g3"
}
if (toolChain in Clang) {
cppCompiler.args "-O0", "-g"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/Od", "/Z7"
}
}
if(buildType == buildTypes.release) {
cppCompiler.define "__NDEBUG__"
if (toolChain in Gcc) {
cppCompiler.args "-Ofast", "-g0"
}
if (toolChain in Clang) {
cppCompiler.args "-Ofast", "-g0"
}
if (toolChain in VisualCpp) {
cppCompiler.args "/O2"
}
}
}
}
}
Though when I run gradle build I get the following error:
Parallel execution is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':linkAnniReleaseExecutable'.
> No static library binary available for library 'openNN' with [flavor: 'default', platform: 'x64', buildType: 'release']
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Can anyone help me with what I'm doing wrong?
(The repo can be found here and the version of the time of posting this question is: e518d77c4d)
I cannot found any example for jax-rs testing with arquillian. I use a wildfly 10 managed container.
I am trying to do it by my own, this is my sample code:
#RunWith(Arquillian.class)
public class DeploymentTest {
#Deployment(testable = false)
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, "cos-arq-test.war")
.addClasses(MANUEJB.class, HelloWorld.class, HelloWorldRESTImpl.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
#ArquillianResource
private URL base;
private static WebTarget target;
#Before
public void setUpClass() throws MalformedURLException {
Client client = ClientBuilder.newClient();
target = client.target(URI.create(new URL(base, "rest/helloWorldREST").toExternalForm()));
}
#Test
#RunAsClient
public void testResponse(#ArquillianResource URL base) throws InterruptedException, ExecutionException {
System.out.println("====================================================");
System.out.println("This test should run inside the Wildfly 10 container");
System.out.println("====================================================");
try {
System.out.println("URL TARGET: " + target.getUri().toURL().toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
assertEquals("Hello", target.request().get().readEntity(String.class));
/*
Future<Response> r1 = target.request().async().get();
Response response = r1.get();
if (null != response) {
assertEquals(HttpStatus.OK, response.getStatus());
assertNotNull(response.getEntity());
assertEquals("Hello " + "manuel" + "!", response.readEntity(String.class));
}
*/
}
}
And this is my service code:
#Path("/helloWorldREST")
public class HelloWorldRESTImpl implements HelloWorld {
#GET
public Response sayHi() {
return Response.ok("Hello").build();
}
#Override
#GET
#Path("/sayHi/{name}")
#Produces(MediaType.APPLICATION_JSON)
public Response sayHi(#PathParam("name") String name) {
MANUEJB ejb = null;
javax.naming.Context initialContext = null;
try {
initialContext = new InitialContext();
} catch (NamingException e) {
e.printStackTrace();
}
try {
ejb = (MANUEJB) initialContext.lookup("java:app/cos-arq-test/MANUEJB");
} catch (NamingException e) {
e.printStackTrace();
}
String result = ejb.method(name);
return Response.ok(result).build();
}
}
But I get an error, and it does not find the service.
I use arquillian libraries with a managed wildfly 10 container:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>2.0.0.Final</version>
</dependency>
And this is my arquillian config for the container:
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="wildfly10" default="true">
<configuration>
<property name="jbossHome">/home/manumg/test-containers/wildfly-10.1.0.Final</property>
</configuration>
</container>
For a starter example, you can see https://github.com/arquillian/arquillian-extension-rest/blob/master/rest-client/README.md.
The code described in the readme is in the same repository at https://github.com/arquillian/arquillian-extension-rest/tree/master/rest-client/test-app.
For a starter maven project, I suggest you using the maven archetype wildfly-jakartaee-webapp-archetype, related to Wildfly 21 (jakarta ee 8 container).
To run the test you have to:
Activate the profile arq-managed
Download Wildfly 21 (from https://www.wildfly.org/downloads/)
Define the JBOSS_HOME variable (pointing to the local Wildfly directory)
I want to make test of some clases in my project.
I'm project is all android, but the new clases are pure Java (I'm trying to make a little sdk for the app)
But I don't know how to configure correctly
Gradle file:
apply plugin: 'android'
android {
compileSdkVersion "Google Inc.:Google APIs:19"
buildToolsVersion "19.0.1"
lintOptions{
checkReleaseBuilds false
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 28
versionName "4.0.5"
}
signingConfigs {
debug {
..........
}
release {
..........
}
}
buildTypes {
debug{
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable true
buildConfigField "boolean", "LOG_ENABLED", "true"
signingConfig signingConfigs.debug
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
buildConfigField "boolean", "LOG_ENABLED", "false"
signingConfig signingConfigs.release
}
}
productFlavors{
develFlavor{
}
testFlavor{
..........
}
trainingFlavor{
..........
}
preFlavor{
..........
}
proFlavor{
.........
}
}
}
if (project.hasProperty('storePassword')) {
android.signingConfigs.release.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
android.signingConfigs.release.keyPassword = keyPassword
}
repositories {
mavenCentral()
}
sourceSets {
test {
java.srcDir file(''src/main/java/es/tempos/gas/sdk/test'')
}
}
dependencies {
unitTestCompile 'junit:junit:4.11'
compile 'com.google.code.gson:gson:1.7.1'
compile 'com.android.support:appcompat-v7:+'
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/sbc_mapslib.jar')
compile files('libs/t21c2dm-lib-v1.0.jar')
}
I want to put the test cases in the folfer Test>SDK
Estructure of the app:
+SmartPhoneGreatApp
----.idea
----app
-----build
-----libs
-----src
-----develFlavor
-----main
----sdk
-----preFlavor
----- .........
........
-----test
------sdk
and the testing class(for the moment do nothing)
package es.tempos21.gas.sdk.test;
import org.junit.Test;
public class AuthenticateTest {
#Test
public void testAuthenticate() throws Exception {
}
}
And the error I'm getting:
Gradle 'SmartPhoneGreatApp' project refresh failed:
Could not find property 'unitTest' on SourceSet container.
Gradle settings
In the Android plugin, sourceSets are configured differently from how the Java plugin does it, so you should read the docs at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies
For testing you'll want to do something like this:
android {
sourceSets {
androidTest.setRoot('tests')
}
}
A shortcut would be to do this instead:
android.sourceSets.androidTest.setRoot('tests')
Note that you're supplying a new top-level directory for where the tests go (and the Java classes will be in a directory structure underneath that corresponds to their package path); in your example you're trying to point it at a package already inside src/main/java/path/to/package, which isn't going to work.