Android studio, gradle tries to download non existed sha1 from maven url - android-studio

I am trying to add library to my project (this one)
I added proper url to build.gradle
repositories {
maven {
url "http://drgames.fr/maven2/"
}
mavenCentral()
}
Then I am trying to use it in project
implementation ('com.ramimartin.multibluetooth:AndroidMultiBluetoothLibrary:2.0.4-SNAPSHOT') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
However, every time I sync project with gradle files, it tries to download metadata for all files under this maven url:
Metadata of http://drgames.fr/maven2/com/android/support/test/espresso/espresso-core/3.0.2/espresso-core-3.0.2.pom 186 ms
Download http://drgames.fr/maven2/com/android/support/test/espresso/espresso-core/3.0.2/espresso-core-3.0.2.pom.sha1 80 ms
Download http://drgames.fr/maven2/com/android/support/test/espresso/espresso-core/3.0.2/espresso-core-3.0.2.pom 71 ms
And the result is tons of errors, during downloading sha1 (but I still can run my app which uses described library and it works):
java.lang.NumberFormatException: For input string: "<html"
When I run building from command line (./gradlew build) there is no errors.
My questions are:
1) What is this magic sha1 file? Why it can't be downloaded and why gradle tries to do it everytime?
2) How to get rid off this errors?

this sha1 file most likely is a HTTP 404 page. just exclude com.android.support.test.espresso from that dependency and substitute it with the default one, from repository mavenCentral():
implementation "com.android.support.test.espresso:espresso-core:3.0.2"
implementation ("com.ramimartin.multibluetooth:AndroidMultiBluetoothLibrary:2.0.4-SNAPSHOT") {
exclude group: "com.android.support.test.espresso", module: "espresso-core"
exclude group: "com.android.support", module: "appcompat-v7"
exclude group: "com.android.support", module: "support-v4"
}

Related

Android Studio: How to exclude Icon\r file?

Google Drive automatically generates Icon$'\r' in each synced folder in OSX. I'd like to exclude this file Icon$'r' recursively from compilation in Android Studio.
I tried #1 (din't work):
Adding !/**/Icon$'\r' and !/**/Icon' in the following field:
File -> Other Settings -> Default Settings
Build, Execution, Deployment -> Compiler
Resource patterns:
I tried #2 (didn't work):
Adding the following in build.gradle under module:
sourceSets {
main {
java {
srcDir 'src'
exclude '**/Icon$"\r"'
// exclude '**/Icon'
}
}
}
Note:
I already excluded Icon$'\r' in .gitignore
If Icon$'\r' is both excluded at compilation AND hidden, that'd be the best solution.

Running Gradle ShadowJar Plugin only on specific subproject

Please note: Even though my myapp-server is a DropWizard app, this is strictly a Gradle question; I only mention DropWizard for good measure.
I have a multi-project build that I am building with Gradle:
myapp/
myapp-client/
myapp-shared/
myapp-server/
build.gradle
settings.gradle
Where settings.gradle looks like:
include ':myapp-shared'
include ':myapp-client'
include ':myapp-server'
I have successfully got Gradle to compile my Groovy source code, run unit tests, generate GroovyDocs, and package both binary and source JARs for all 3 subprojects. The build invocation for which is: gradle clean build groovydoc sourcesJar -Pversion=<whatever version I specify>.
The myapp-server is actually a project that I need to run the Shadow JAR plugin on, which is usually executed via gradle clean build shadowJar.
Here is my myapp-server/build.gradle:
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
apply plugin: 'application'
apply plugin: 'shadow'
mainClassName = 'com.me.myapp.server.MyAppServer'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:0.8'
}
}
dependencies {
compile project(':myapp-shared')
compile (
'io.dropwizard:dropwizard-core:0.7.1'
)
}
shadow {
outputFile new File(destinationDir, "${outputJarBaseName}.${extension}")
transformer(ServiceFileTransformer)
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}
run {
args 'server', 'config.json'
if (System.getProperty('debug', 'false') == 'true') {
jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
}
}
artifacts {
shadowJar
}
My question: How do I configure Gradle to only run the shadowJar task on my myapp-server subproject, and not on any of the others? Ideally, I could just have my build invocation be something like:
gradle clean build groovyDoc sourceJar shadowJar -Pversion=<blah>
And then somehow configure Gradle to ignore running shadowJar on everything except myapp-server. Ideas?
Update
When I run gradle clean build groovyDoc sourceJar shadowJar -Pversion=0.1.3 I see a bunch of Gradle output that ends with:
:myapp-shared:groovydoc
:myapp-client:sourcesJar
:myapp-server:sourcesJar
:myapp-shared:sourcesJar
:myapp-server:copySignedLibs UP-TO-DATE
:myapp-server:shadowJar
BUILD SUCCESSFUL
Total time: 16.315 secs
However when I drill down into myapp-server/build/libs/myapp-server-0.1.3.jar and open it (extracting it like a ZIP), I only see my compiled classes inside of it, not all the classes from all of its dependent JARs (it should be a "Fat JAR"). For instance, myapp-server depends on DropWizard. All the DropWizard classes should be inside this JAR. All of DropWizard's transitive dependencies should have class files inside this JAR, etc.
I've just checked out the project located here.
After fetching the sources I've run: gradle clean shadowJar in myapp directory. As far as I see, there is a jar file created under myapp/myapp-server/build/distributions that seesm to be the fat jar You're looking for (also when file size is taken into consideration). After entering the mentioned distributions directory and running java -jar myapp-server.jar the server is started. It seems that it's all working fine. Am I right?
Also running curl -v -X GET http://localhost:8080/myapp/dosomething gives the following output:
* Hostname was NOT found in DNS cache
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /myapp/dosomething HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 05 Jan 2015 14:59:50 GMT
< Content-Type: application/json
< Content-Length: 0
<
* Connection #0 to host localhost left intact
If you were looking to only reference one sub project to shadowJar you could do it as follows.
gradle clean build groovyDoc sourceJar :myapp-server:shadowJar -Pversion=<1.0>
You can drill down to your subprojects tasks via :<project name>:<task name>
Reference:
https://gradle.org/docs/current/userguide/multi_project_builds.html
57.4. Running tasks by their absolute path

Specify ivy configuration in gradle dependency

I want to resolve dependencies from ivy repository but I don't know how to specify ivy configuration for it. I found that I should do it in this way:
myconf group: 'com.eu', module:'MyModule', version:'1.0.0', configuration: 'ivyconf'
but it doesn't work. When I run gradle dependencies command gradle returns this error:
Could not create a dependency using notation: {group=com.eu, module=MyModule, version=1.0.0, configuration=ivyconf}
My build doesn't use plugins. I want to download dependencies in simple build which should create product from downloaded dependencies.
Build looks like this:
group = 'com.eu'
version = '0.9a'
configurations {
myconf
}
repositories {
ivy {
url 'http://ivyrepo.local/ivyrep/shared'
layout "pattern", {
artifact "[organisation]/[module]/[revision]/[type]s/[artifact].[ext]"
}
}
}
dependencies {
myconf group: 'com.eu', module:'MyModule', version:'1.0.0', configuration: 'ivyconf'
}
Instead of module, it has to be name. (see "49.4. How to declare your dependencies" in the Gradle User Guide). The declared configuration (myConf) must match the configuration used in the dependencies block (installer).

Create multiple .WAR files with different dependencies in Gradle

I am using the war plugin to generate a simple .WAR file for my project in gradle. I'd like to know how to configure gradle so that I can create 4 different .WAR files with different dependencies.
I've configured the dependency compile configuration with the jars that are needed to go into the distribution. None of the code in the src depends on a couple of these jars but I would like to know how to configure the project to create
a standard.WAR file that contains all of the jars in the dependency graph (Even though they aren't used - that is OK - I am testing something)
another standard-qas-only.WAR file that only contains the qas.jar
another standard-qas-log4j.WAR file that contains qas.jar and log4j
What tasks do i configure to have the artifact generated use a particular dependency configuration?
FYI: The only jar that is required for compilation is qas.jar in this case.
My example below creates a war file that only includes one jar but i'd like to have 5 different .war files generated with different jars.
build.gradle
apply plugin: 'java'
apply plugin: 'war'
dependencies {
compile files('/lib/qas.jar','/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar','/lib/log4j-1.2.14.jar')
providedCompile files('/lib/j2ee-1.4.03.jar')
}
war {
classpath = ['/lib/qas.jar']
}
task dist(dependsOn: 'war') << {
copy {
from war.archivePath
into "dist/"
}
}
I got a bit confused on how many WAR distributions you are actually trying to build. You can easily modify it to create additional WAR files. Here's one approach to make this happen:
task createStandardWar(type: War, dependsOn: classes) {
baseName = 'standard'
destinationDir = file("$buildDir/dist")
}
task createStandardWarQasOnly(type: War, dependsOn: classes) {
baseName = 'standard-qas-only'
destinationDir = file("$buildDir/dist")
classpath = war.classpath.minus(files('/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar','/lib/log4j-1.2.14.jar'))
}
task createStandardWarQasAndLog4J(type: War, dependsOn: classes) {
baseName = 'standard-qas-log4j'
destinationDir = file("$buildDir/dist")
classpath = war.classpath.minus(files('/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar'))
}
task createDists(dependsOn: [createStandardWar, createStandardWarQasOnly, createStandardWarQasAndLog4J])
This build script excerpt creates three different WAR files by declaring enhanced tasks of type War. It assumes that you still want to have your compiled source files under WEB-INF/classes within the WAR files so I didn't remove it from the classpath. The distributions end up in the directory build/dist. The task createDists creates all of them.

Gradle zip packaging: copy Jar file from repository

I have to copy a jar from the repository (say local) in my ZIP packaging. I understand that we can define compile/runtime in dependencies. However, I could not use it them in ZIP.
I'm able to copy the jar file by specifying the path in my filesystem. However, I don't know how to do it from repository.
Here is how my code looks like:
task createZipFile (type: Zip, dependsOn: [...]) {
baseName 'xyz'
from(fileTree("src/main"), {
include "prjName/css/**"
include "prjName/images/**"
include "prjName/javascript/**"
include "prjName/WEB-INF/**"
exclude "prjName/WEB-INF/web.xml"
})
from file("<Absolute-path-to-jar-file-in-my-filesystem>") //this works
// how to copy the same jar file from repository ??
}
Assuming your dependencies are in the runtime configuration ie:
runtime 'org.slf4j:slf4j-log4j12:1.6.2'
you can do:
task createZipFile( type: Zip, dependsOn: [...] ) {
baseName 'xyz'
from fileTree("src/main"), {
include "prjName/css/**"
include "prjName/images/**"
include "prjName/javascript/**"
include "prjName/WEB-INF/**"
exclude "prjName/WEB-INF/web.xml"
}
from configurations.runtime.files { it.name == 'slf4j-log4j12' }
}
To add all jars downloaded for the dependency with the name slf4j-log4j12
To specify a specific jar without its dependencies, qualify it with "#jar". E.g.
"commons-beanutils:commons-beanutils:1.6#jar"
For an example that explains how to reference a set of jars using a custom configuration, see Download some dependencies and copy them to a local folder

Resources