Why the gradle war task is skipped? - android

I am a new convert to Gradle. Most of the tasks work fine. However, I see that the war task is always skipped. When I run in the debug mode, I see the following logs -
09:12:34.889 [LIFECYCLE] [class
org.gradle.internal.buildevents.TaskExecutionLogger] :war 09:12:34.889
[DEBUG]
[org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]
Starting to execute task ':war' 09:12:34.889 [INFO]
**[org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter] Skipping task ':war' as task onlyIf is false.** 09:12:34.889 [DEBUG]
[org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]
Finished executing task ':war' 09:12:34.889 [LIFECYCLE] [class
org.gradle.internal.buildevents.TaskExecutionLogger] :war SKIPPED
I am not sure why onlyIf is false. I did search on internet. But I did not find anything related.
Here is my Gradle file -
buildscript {
ext {
springBootVersion = '2.0.0.M2'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.retry:spring-retry:1.2.1.RELEASE")
compile("org.springframework.data:spring-data-cassandra:2.0.0.M4")
compile("io.reactivex.rxjava2:rxjava:2.1.1")
//compile("javax.persistence:persistence-api:1.0.2")
//compile("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.zaxxer:HikariCP:2.6.0")
// Test Dependencies
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.powermock:powermock-mockito-release-full:1.6.4")
testCompile("org.mockito:mockito-core:2.0.3-beta")
testCompile("org.cassandraunit:cassandra-unit:3.1.3.2")
testCompile("org.cassandraunit:cassandra-unit-spring:2.2.2.1")
testCompile("com.h2database:h2:1.4.196")
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
testImplementation 'junit:junit:4.12'
}
Here is the image of my project structure -
If you could help me with generating the war file that would be great.

try it
war {
enabled = true
}

I have also faced same issue with jar task, it is skipping the jar generation as it is taking the default value for enabled=false if you dont specify any external value.
Same solution works for jar as well based on #Alexander Servetnik
Enrironment:
SpringBoot 2.x and
gradle 4.4
jar {
baseName = <your-jar name>
enabled=true
}

Try upgrading gradle version
Spring Boot’s Gradle plugin requires Gradle 6 (6.3 or later). Gradle 5.6 is also supported but this support is deprecated and will be removed in a future release.
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/

This is because the Springboot Gradle plugin will create a bootJar task and by default will disable jar and war task.
You can enable this, by adding the below code in projectName.gradle
jar {
baseName = 'projectName'
enabled=true
manifest {
....
}
}

Related

Not able to upload android library to JitPack.io. Failed to apply plugin [id 'com.android.internal.version-check']

I have made an android library and uploaded to Github. (https://github.com/Shekhar23/TxtLogSdk)
Now I want to add to jitpack.io. But I get an error!
How can I upload to jitpack.io?
Build log : https://jitpack.io/com/github/Shekhar23/TxtLogSdk/2.1/build.log
A problem occurred evaluating project ':app'.
Failed to apply plugin [id 'com.android.internal.version-check']
Minimum supported Gradle version is 6.1.1. Current version is 4.8.1. If using the gradle wrapper, try editing the distributionUrl in /home/jitpack/build/gradle/wrapper/gradle-wrapper.properties to gradle-6.1.1-all.zip
Initially I also had this error with Gradle 4.8.1, which was for sure confusing:
Found gradle
Gradle build script
WARNING: gradle/wrapper/gradle-wrapper.jar does not exist! Needs to be committed.
ERROR: Gradle wrapper not found. Please add. Using default gradle to build.
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Welcome to Gradle 4.8.1!
See build.log for details.
What I actually missed, is including ./gradlew and ./gradle/wrapper/gradle-wrapper.jar into the git repository. Yes! You should upload these files to github!
After that you can use the latest gradle version, which is awesome!
Here is the build log:
Found gradle
Gradle build script
Found gradle version: 6.5.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-6.5-all.zip
...
------------------------------------------------------------
Gradle 6.5
See build.log for details.
Actually this information is in the official manual https://jitpack.io/docs/ANDROID/ , but the requirement for uploading the gradle-files is not totally clear described.
Comment in this issue was very helpful: https://github.com/jitpack/jitpack.io/issues/2311
P.S. Plugin com.github.dcendents.android-maven should be included to two build.gradle-files as described in the manual.
Did you update your Gradle files?
You should have something similar like the config below:
settings.gradle
include ':app', ':NAME_OF_LIBRARY'
rootProject.name = "NAME_OF_LIBRARY"
build.gradle (module)
Add the plugin, group and version
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.YOURGITHUBNAME'
version = rootProject.ext.versionName
...
build.gradle (project)
Add the github classpath to your dependencies
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
allprojects {
repositories {
google()
jcenter()
...
}
}
ext {
compileSdkVersion = 29
buildToolsVersion = '29.0.2'
versionName = '1.0.0'
...
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Firebase unresolved supertype with Kotlin on Android

I'm experiencing a problem in my project that uses Firebase core and messaging v11.4.2.
The gradle sync works perfectly but then I get this error when compiling:
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.google.android.gms.internal.zzctr, unresolved supertypes: com.google.android.gms.internal.zzee
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ‘:app:compileDebugKotlin’.
Compilation error. See log for more details
I've tried both with Kotlin version 1.1.51 and 1.2.0-beta-88; Gradle plugins v2.3.3 and 3.0.0
Any help is welcomed, thanks a lot!
This is how I've configured the project:
app build.gradle
// tried adding and removing the -kapt and -android-extensions. Didn't help.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
debug {
/// added this to be sure the class was not being left out
minifyEnabled false
shrinkResources false
useProguard false
}
...
dependencies {
// Firebase Core
implementation "com.google.firebase:firebase-core:${rootProject.ext.firebaseVersion}"
// Firebase Cloud Messaging
implementation "com.google.firebase:firebase-messaging:${rootProject.ext.firebaseVersion}"
}
...
// Keep this as the last line or the build will fail
apply plugin: 'com.google.gms.google-services'
* project build.gradle *
buildscript {
// App
ext.compileSdkVersion = 26
ext.minSdkVersion = 18
ext.buildToolsVersion = '26.0.2'
ext.targetSdkVersion = 26
// Kotlin beta, stable version doesn't compile either
ext.kotlin_version = '1.2.0-beta-88'
// Android
ext.androidSupportVersion = '26.1.0'
//TODO: implement LifecycleOwner interface from Architecture Components.
ext.lifecycleVersion = '1.0.0-beta2'
// Architecture, RxJava, Injection
ext.daggerVersion = '2.11'
ext.butterKnifeVersion = '8.8.1'
ext.rxJavaVersion = '2.1.0'
ext.rxAndroidVersion = '2.0.1'
// Google/Firebase Cloud Message
ext.firebaseVersion = '11.4.2'
// Libraries shared between modules (TODO)
}
repositories {
maven { url 'https://maven.google.com' } // Google Maven Repository
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2'} // Kotlin beta
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
//// tried this too: classpath 'com.google.firebase:firebase-plugins:1.1.1'
}
allprojects {
repositories {
jcenter()
mavenLocal()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2'}
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
mavenCentral()
flatDir {
dirs 'libs'
}
}
Turns out the problem was an incompatible version of the Google Wallet library, being implemented by another dependency of the project and conflicting with the one imported by the com.google.gms.google-services plugin.
For some reason gradle didn't state this problem and I had to go through the code until I found the place where Wallet was trying to access a class that was successfully importing but at the same time it couldn't be found.
Simply by updating the version in the other module everything was fixed :)

Gradle: how to include an existing, complete project as a subproject?

I git clone a complete gradle project "CompleteGradleProjA" from github and include it into my local project as a submodule. By "complete gradle project" I mean that I can go into directory "CompleteGradleProjA" and issue command
cd CompleteGradleProjA && gradle build
to build it.
My directory structure looks like this,
MyProj
|---CompleteGradleProjA
| |---build.gradle
|
|---build.gradle
My question is: How can I call "CompleteGradleProjA/build.gradle" without changing anything of it from my root "build.gradle"?
The following root "build.gradle" config does not help.
apply plugin: 'java'
dependencies {
compile project(':CompleteGradleProjA')
}
I got error message
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':compileJava'.
> Could not determine the dependencies of task ':compileJava'.
"CompleteGradleProjA" is an android porject and "CompleteGradleProjA/build.gradle" looks like this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
CompleteGradleProjA/build.gradle
apply plugin: 'com.android.library'
// if your project isn't library then use this:
// apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0' // if needed
}
settings.gradle
include ':CompleteGradleProjA'
Use apply plugin: 'com.android.library' or apply plugin: 'com.android.application' instead of apply plugin: 'java'
To include a custom project as part of your gradle build, first ensure the submodule is already included within the project folder and accessible via your settings.gradle. i.e.
include ':app', ':your_project_name'
You then register the project as a dependency of another by using in your project's build.gradle:
dependencies {
compile project(path: ':your_project_name')
}
In newer versions compile has been deprecated. See here on what to use.

Get Android gradle plugin & checkstyle working together / command line usage

I'm evaluating the ability of the new gradle-based build system to reproduce our current ant-based build process and, as a gradle beginner, I failed to get checkstyle running with the android gradle plugin.
Environment:
gradle 1.6 running fine on a standard java project (checkstyle check target included)
up-to-date android SDK (22.0.1 with platform tools and build tools 17)
no eclipse, no android studio, only my lovely terminal
Symptom:
The target project is https://github.com/nibua-r/LigoTextDemo and I succeeded to build it using gradle but if I naively add apply plugin: checkstyle to my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
apply plugin: 'checkstyle'
android {
buildToolsVersion '17'
compileSdkVersion 15
testBuildType 'debug'
defaultConfig {
versionCode = 1
versionName = '1.0'
minSdkVersion 12
targetSdkVersion 15
}
buildTypes {
debug {
packageNameSuffix = '.debug'
}
}
}
then gradle check doesn't even complain on not finding the checkstyle.xml file (at the default config/checkstyle location) and returns:
:check UP-TO-DATE
BUILD SUCCESSFUL
What's needed:
First, I just need a running checkstyle target. Then, I need to automate checkstyle running as a dependency of the compilation (but lets get the chekstyle target up and running first).
Assumption:
This may be related to the fact that (from the [user guide][1]):
The Android plugin […] uses its own sourceSets
but I'm not enough gradle-efficient to understand what I'm missing there. Please, gradle Master, enlighten me with your valuable knowledge!
I got pmd, findbugs, and checkstyle working with Gradle 1.12 android plugin 0.12.+ using the following script:
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'
check.dependsOn 'checkstyle', 'findbugs', 'pmd'
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
}
task findbugs(type: FindBugs) {
ignoreFailures = true
effort = "max"
reportLevel = "high"
excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml")
classes = files("$project.buildDir/intermediates/classes/")
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml {
destination "$project.buildDir/reports/findbugs/findbugs.xml"
xml.withMessages true
}
}
classpath = files()
}
task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")
ignoreFailures = true
ruleSets = ["basic", "braces", "strings"]
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = true
html.enabled = false
}
}
Running gradle build in command line will run all code quality plugins and generate xml reports in app/build/reports/ which are then ready to be viewed or parsed by CI tools.
Someone has a great answer to solve integrating PMD, findbugs and checkstyle with Gradle for Android.
Unfortunately, the only solution for now is based on ant :
http://sethrylan.org/2013/07/14/gradle-android-findbugs.html
I wish gradle will one day allow to do as much as maven for Android.
--- Update as of October 2013
With Gradle 1.8 and Android plugin for Gradle 0.6.+, you don't need this anymore. Android sourcesets and configurations are now compatible with the java plugin and all quality plugin work out of the box.
This includes pmd, findbugs, checkstyle and classycle.
--- Update
A configuration, largely inspired from the project mentioned above, is proposed in this open source project as well, plus other tools.
To get this to work with my Android project, I had to declare the task explicitly.
Here's what worked for me:
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
source 'src'
include '**/*.java'
exclude '**/gen/**'
// empty classpath
classpath = files()
}
Be mindful that the Android plugin may choose to create a task of the same name in the future or work in conjunction with the checkstyle plugin in different ways.
You can try Android Check plugin (https://github.com/noveogroup/android-check):
Checkstyle
PMD
Configuration:
buildscript {
repositories { jcenter() }
dependencies {
...
classpath 'com.noveogroup.android:check:+'
...
}
}
apply plugin: 'com.noveogroup.android.check'
You can use hardcore configuration:
check {
abortOnError true
checkstyle { config hard() }
pmd { config hard() }
}
I found by digging on the web that the Android plugin depends on java-base and not java (i.e. the sourceSets management is specific) and the checkstyle plugin rely on java. As a consequence, some gradle upstream modification are needed to get the thing done. The gradle team is working on that, as seen on twitter:
#anzix Android source sets will be soon understood by the generic code quality plugins. Work on that has already started.— Gradle Build System (#Gradleware) May 26, 2013
Take a look at the Soter Gradle plugin to semlessly add support for Findbugs, Checkstyle and PMD to Android projects.

Android Scala and Gradle

I am new to Gradle. Is there some example how to configure properly gradle-android-plugin for scala classes.
this is what I have now.
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.gradle.api.plugins:gradle-android-plugin:1.2.1' }
}
apply plugin: 'android'
apply plugin: 'eclipse'
apply plugin: 'scala'
sourceCompatibility = 1.6
version = "1.0.0"
repositories { mavenCentral() }
dependencies {
compile files('/home/pcu/workspace/workspace-android/emoo/libs/android-support-v4.jar')
compile 'org.scala-lang:scala-library:2.9.1'
scalaTools 'org.scala-lang:scala-compiler:2.9.1'
scalaTools 'org.scala-lang:scala-library:2.9.1'
}
task configureDebug << { jar.classifier = "debug" }
task configureRelease << { proguard.enabled = true }
but compilation fails. Scala class is not compiled.
It is actually much simpler with the right plugin:
https://github.com/saturday06/gradle-android-scala-plugin
This worked perfectly fine for me.
You need only about 3 more lines in your gradle configuration and potentially proguard to reduce the apk size.
The setup is well documented on the github page. Everything beyond steps 1-3 is optional.

Categories

Resources