Gradle settings groovy file to kts file - gradle-plugin

I have this as settings.gradle
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.net.vivin:gradle-semantic-build-versioning:4.0.0'
}
}
apply plugin: 'net.vivin.gradle-semantic-build-versioning'
I need to convert it to a settings.gradle.kts kotlin DSL file. I tried:
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.net.vivin:gradle-semantic-build-versioning:4.0.0")
}
}
apply ("gradle.plugin.net.vivin.gradle-semantic-build-versioning")
This gives the error:
Cannot apply plugin of class 'org.gradle.api.Plugin' to
'net.vivin.gradle-semantic-build-versioning' (class: java.lang.String)
as it does not implement PluginAware
What is the problem here?

The solution is:
plugins.apply("net.vivin.gradle-semantic-build-versioning")

Related

deploying a SpringMvcPortlet in a gradle project

im using liferay 7.1 ,and when i want to deploy a SpringMvcPortlet i got this error :
Could not resolve all files for configuration ':wars:mySpringMvcPortlet:compileClasspath'.
Could not find javax.validation:validation-api:.
Required by:
project :wars:SpringMvcPortletFormation
Could not find org.hibernate.validator:hibernate-validator:.
Required by:
project :wars:SpringMvcPortletFormationPossible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Do you have an idea where my error is?
Thanks in advance
You have a dependency issue here, you have to manage all your dependency for the SpringMvcPortletFormationPossible project, and you need to put them properly in the build.gradle file,
So I recommand to add mavenLocal() to the repositories { } to be able to search all the local dependencies from the local repo and find them properly:
Example:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "3.13.8"
}
repositories {
mavenLocal()
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "com.liferay.plugin"
dependencies { .... // your dependency here // .... }
repositories {
mavenLocal()
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}

Using SCSS in spring boot with freemarker and gradle

So I have a spring boot project that is using freemarker and is built using gradle.
This is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'application'
}
group = 'some.project'
version = '4'
mainClassName = "some.project.Application"
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
}
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
}
jar {
// include all the jars
from {
(configurations.runtime).collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'some.project.Application'
}
}
I have decided to start using scss because my css files were becoming a little difficult to manage and keep consistent. However I can't seem to figure out how to get my application to load up scss files. All the scss files are located in resources/static/scss, what should I do with them so that they become css and readable by my spring boot application and freemarker?

React Native build fails after add firebase setup

I need to set up my react-native app with firebase and I followed the firebase setup guide and after that rerun the app but it fails with giving me errors, I tried lots of solutions that available on the internet but still my issue is not fixed.
if anyone have got this issue before and fixed it already, could you please help me to fix this issue.
this is the error:
* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not find com.google.android.gms:play-services-measurement:12.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
- https://jitpack.io/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
- https://jitpack.io/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
Required by:
project :app > com.google.firebase:firebase-analytics:17.2.0
> Could not find com.google.android.gms:play-services-measurement-api:12.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
- https://jitpack.io/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
- https://jitpack.io/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
Required by:
project :app > com.google.firebase:firebase-analytics:17.2.0
> Could not find com.google.android.gms:play-services-measurement-sdk:12.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
- https://jitpack.io/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
- https://jitpack.io/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
Required by:
project :app > com.google.firebase:firebase-analytics:17.2.0
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "+"
}
repositories {
google()
maven { url "https://maven.google.com" }
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
maven { url "https://maven.google.com" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
jcenter()
maven { url 'https://jitpack.io' }
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
}
#AjithMadhu I found the issue, it because of the below section. I hardcoded before a month ago and I didn't notice that one.
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.google.android.gms'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "12.0.1"
}
}
}
}
well this is how I done. please refer this,
android/build.gradle
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
+ classpath 'com.google.gms:google-services:4.3.3' // check this line
}
android/app/build.gradle
dependencies {
+ implementation "com.google.android.gms:play-services-base:17.1.0"
+ implementation 'com.google.firebase:firebase-core:17.2.1'
+ implementation 'com.google.firebase:firebase-messaging:20.0.1'
}
android/
grade.properties
firebaseCoreVersion=17.2.1
firebaseMessagingVersion=20.0.1
MainApplication.java
+ import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
+ import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new RNFirebaseMessagingPackage());
packages.add(new RNFirebaseNotificationsPackage());
return packages;
}

Gradle - get artifact from repository and use it

The problem:
I have a jar in some repository.
I want to run the jar and do something with it during gradle task.
The attempt:
apply plugin: 'java'
repositories {
maven {
url "<<<valid repo url>>>"
}
mavenCentral()
}
dependencies {
compile(group: 'com.google.developers', name: 'compiler', version: 'v20150315', ext: 'pom')
}
task doTheJar {
dependsOn configurations.compile
exec {
executable "sh"
args "-c","java -jar <<the-artifact>> smoething something"
}
}
Is there a way to do it?
Is there a way to do it without java plugin?
Thanks.
It will be better to do it in the following way:
apply plugin: 'java'
repositories {
maven {
url "<<<valid repo url>>>"
}
mavenCentral()
}
configurations {
runjar
}
dependencies {
runjar 'some:artifact:1.0'
}
task runTheJar(type: JavaExec) {
main 'main.class.to.be.run'
classpath configurations.runjar
args 's1', 's2', 's3'
}

gradle - download and unzip file from url

What would be the proper gradle way of downloading and unzipping the file from url (http)?
If possible, I'd like to prevent re-downloading each time I run the task (in ant.get can be achieved by skipexisting: 'true').
My current solution would be:
task foo {
ant.get(src: 'http://.../file.zip', dest: 'somedir', skipexisting: 'true')
ant.unzip(src: 'somedir' + '/file.zip', dest: 'unpackdir')
}
still, I'd expect ant-free solution. Any chance to achieve that?
Let's say you want to download this zip file as a dependency:
https://github.com/jmeter-gradle-plugin/jmeter-gradle-plugin/archive/1.0.3.zip
You define your ivy repo as:
repositories {
ivy {
url 'https://github.com/'
patternLayout {
artifact '/[organisation]/[module]/archive/[revision].[ext]'
}
// This is required in Gradle 6.0+ as metadata file (ivy.xml)
// is mandatory. Docs linked below this code section
metadataSources { artifact() }
}
}
reference for required metadata here
The dependency can then be used as:
dependencies {
compile 'jmeter-gradle-plugin:jmeter-gradle-plugin:1.0.3#zip'
//This maps to the pattern: [organisation]:[module]:[revision]:[classifier]#[ext]
}
To unzip:
task unzip(type: Copy) {
def zipPath = project.configurations.compile.find {it.name.startsWith("jmeter") }
println zipPath
def zipFile = file(zipPath)
def outputDir = file("${buildDir}/unpacked/dist")
from zipTree(zipFile)
into outputDir
}
optional:
If you have more than one repository in your project, it may also help (for build time and somewhat security) to restrict dependency search with relevant repositories.
Gradle 6.2+:
repositories {
mavenCentral()
def github = ivy {
url 'https://github.com/'
patternLayout {
artifact '/[organisation]/[module]/archive/[revision].[ext]'
}
metadataSources { artifact() }
}
exclusiveContent {
forRepositories(github)
filter { includeGroup("jmeter-gradle-plugin") }
}
}
Earlier gradle versions:
repositories {
mavenCentral {
content { excludeGroup("jmeter-gradle-plugin") }
}
ivy {
url 'https://github.com/'
patternLayout {
artifact '/[organisation]/[module]/archive/[revision].[ext]'
}
metadataSources { artifact() }
content { includeGroup("jmeter-gradle-plugin") }
}
}
plugins {
id 'de.undercouch.download' version '4.0.0'
}
/**
* The following two tasks download a ZIP file and extract its
* contents to the build directory
*/
task downloadZipFile(type: Download) {
src 'https://github.com/gradle-download-task/archive/1.0.zip'
dest new File(buildDir, '1.0.zip')
}
task downloadAndUnzipFile(dependsOn: downloadZipFile, type: Copy) {
from zipTree(downloadZipFile.dest)
into buildDir
}
https://github.com/michel-kraemer/gradle-download-task
There isn't currently a Gradle API for downloading from a URL. You can implement this using Ant, Groovy, or, if you do want to benefit from Gradle's dependency resolution/caching features, by pretending it's an Ivy repository with a custom artifact URL. The unzipping can be done in the usual Gradle way (copy method or Copy task).
Unzipping using the copy task works like this:
task unzip(type: Copy) {
def zipFile = file('src/dists/dist.zip')
def outputDir = file("${buildDir}/unpacked/dist")
from zipTree(zipFile)
into outputDir
}
http://mrhaki.blogspot.de/2012/06/gradle-goodness-unpacking-archive.html
This works with Gradle 5 (tested with 5.5.1):
task download {
doLast {
def f = new File('file_path')
new URL('url').withInputStream{ i -> f.withOutputStream{ it << i }}
}
}
Calling gradle download downloads the file from url to file_path.
You can use the other methods from other answers to unzip the file if necessary.
I got #RaGe's answer working, but I had to adapt it since the ivy layout method has been depreciated see
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.repositories.IvyArtifactRepository.html#org.gradle.api.artifacts.repositories.IvyArtifactRepository:layout(java.lang.String,%20groovy.lang.Closure)
So to get it working I had to adjust it to this for a tomcat keycloak adapter:
ivy {
url 'https://downloads.jboss.org/'
patternLayout {
artifact '/[organization]/[revision]/adapters/keycloak-oidc/[module]-[revision].[ext]'
}
}
dependencies {
// https://downloads.jboss.org/keycloak/4.8.3.Final/adapters/keycloak-oidc/keycloak-tomcat8-adapter-dist-4.8.3.Final.zip
compile "keycloak:keycloak-tomcat8-adapter-dist:$project.ext.keycloakAdapterVersion#zip"
}
task unzipKeycloak(type: Copy) {
def zipPath = project.configurations.compile.find {it.name.startsWith("keycloak") }
println zipPath
def zipFile = file(zipPath)
def outputDir = file("${buildDir}/tomcat/lib")
from zipTree(zipFile)
into outputDir
}
"native gradle", only the download part (see other answers for unzipping)
task foo {
def src = 'http://example.com/file.zip'
def destdir = 'somedir'
def destfile = "$destdir/file.zip"
doLast {
def url = new URL(src)
def f = new File(destfile)
if (f.exists()) {
println "file $destfile already exists, skipping download"
} else {
mkdir "$destdir"
println "Downloading $destfile from $url..."
url.withInputStream { i -> f.withOutputStream { it << i } }
}
}
}

Resources