When does .m2 folder gets created while using gradle with Java - java

I am currently working on Java with gralde where the build.properties file looks like this
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'groovy'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
//Artifactory Central Repository
buildscript {
repositories {
maven {
url 'abc'
credentials {
username = ""
password = ""
}
I am totally new to this framework and have the following questions:
Here, I understand that the dependencies are getting downloaded from the maven repository. And wondering if .m2 folder will be created when I execute this. or will this work without creating .m2 local repo.
I read that local repo is needed only for maven, not grade.
So, in this case where Gradle is used to access maven repo to download dependencies, is .m2 folder needed.
When does this .m2 folder gets created?
After the Gradle build is successful, I did check in my {user home} but there are no .m2 created
I did try getting info from Google but didn't get any clarity on this.
confused on how does Gradle uses .m2 while building its project.

Related

Intellij Idea thinks Spring project is Android project

I have a gradle spring java project setup, after weeks of it working, Idea suddenly thinks it is an android project, keeps asking me for Android SDK, after deleting .gradle and out/ folders and setting JDK in settings, it compiles and starts, but doesn't copy application.properties file that is required to run the app. Tried restarting, deleting .gradle, .idea, and any other output folder that I could find, but it seems like the only solution that temporarily helps is to clone the repository to a new folder. My suspicion is that I have something in my gradle file that tricks idea to think it's android, but couldn't find anything.
My build.gradle
import org.springframework.boot.gradle.plugin.SpringBootPlugin
buildscript {
ext {
springVersion = "4.3.12.RELEASE"
springBootVersion = '2.1.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.ebean:ebean-gradle-plugin:11.34.1")
}
}
apply plugin: SpringBootPlugin
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.ebean'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-data-rest:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-websocket:${springBootVersion}")
implementation("org.mindrot:jbcrypt:0.3m")
implementation('io.jsonwebtoken:jjwt-api:0.10.5')
runtime "io.jsonwebtoken:jjwt-impl:0.10.5", "io.jsonwebtoken:jjwt-jackson:0.10.5"
implementation("org.springframework:spring-jdbc:${springVersion}")
implementation("org.apache.logging.log4j:log4j-core:2.11.1")
implementation("org.postgresql:postgresql:42.2.5")
implementation("org.apache.tomcat:tomcat-jdbc:9.0.8")
implementation("io.ebean:ebean:11.36.1")
implementation("io.ebean:ebean-agent:11.11.1")
implementation("io.ebean:ebean-spring-txn:11.10.4")
testImplementation("junit:junit:'4.+")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
Clean IDE project specific files and regenerate them with
./gradlew cleanIdea idea
Then try to import project again.

InteliJ -- Gradle 'test' project refresh failed Error:Error:Could not create parent directory for lock file

I am new to Gradle, I am using InteliJ, just start a new project using using Gradle, when I try to refresh my build.gradle, it says
Gradle 'test' project refresh failed
Error:Error:Could not create parent directory for lock file C:\Program Files\gradle-2.7\wrapper\dists\gradle-3.5-rc-2-bin\ktl4k9rdug30mawecgppf5ms\gradle-3.5-rc-2-bin.zip.lck
Any ideas how to fix this?
this is my build.gradle
group 'com.maxinrui'
version '1.0-SNAPSHOT'
buildscript{
repositories{
mavenCentral()
}
dependencies{
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE'
}
}
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.2.6.RELEASE'
}
I think issue with your classpath, check your build path. if not set then you need to set. You can set classpath 'com.android.tools.build:gradle:2.3.0'
and add distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip into gradle-wrapper.properties file.
Then sync your project.

Gradle config to custom plugin

I'm trying to get a better understanding of what is possible to do with gradle plugins. I've done some reading on https://docs.gradle.org/current/userguide/custom_plugins.html, but
I do not feel like it answers my questions.
Right now we have several projects that are built into ear files with the ear-plugin.
However, for all our ear-projects we have a bunch of other config that we at the moment have in a company_ear.gradle file
that we apply in the build.gradle file of our ear-projects.
example of our company_ear.gradle:
allprojects {
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
}
apply plugin: 'ear'
ear {
appDirName 'application'
rename('([^-]*)(.*)(.war)', '$1$3')
rename('([^-]*)(.*)(.jar)', '$1$3')
}
task devDeploy (type: Copy, dependsOn: assemble) {
//code to do local deploy of ear
}
// More custom stuff that should apply to all ear-projects
So my question is, is it possible to move this to a custom gradle plugin so I can just do "apply plugin: company-ear"? I understand how to do the "devDeploy" task
in a plugin but I can not understand how I would fix the allProjects, apply plugin: 'ear', and ear-block in a custom plugin.

Make Gradle use Maven local repository for downloading artifacts

I know I can configure Gradle to use local Maven repository
repositories {
mavenLocal()
mavenCentral()
}
Can I configure Gradle to download into Local (maven) repository? (So that Maven would also be able to use those jars)
ref Gradle configuration to use maven local repository
A solution was given in the gradle forums:
https://discuss.gradle.org/t/need-a-gradle-task-to-copy-all-dependencies-to-a-local-maven-repo/13397/2
using this gradle plugin: https://github.com/ysb33r/ivypot-gradle-plugin
you can call a new tasg
gradle syncRemoteRepositories
which will download all dependencies to a local Ivy repository (which is the same library Maven uses). The folder you point to with
syncRemoteRepositories {
repoRoot '/path/to/repo'
}
will contain the dependencies. I would suggest first trying out with a different local path than your M2_HOME, because I saw some warning about the Ivy repository structure having changed between Maven versions.
It should be as simple as
apply plugin: 'maven'
apply plugin: 'java'
dependencies {
mavenLocal()
}
And
gradle install
More info here

Gradle create war and jar from same project

Im creating a java rest service using spring mvc, gradle and tomcat. I want to create a war from this project to be deployed in tomcat, and I want a jar from all model packages. I managed to create war and it works well. But I don't know to create a jar from my specified classes to be used as a client jar. I know i have to use include('com/a/b/**/model/**') for selecting classes but thats all. This jar i want to be installed in .m2 local repo so it can be used as a dependency for another projects. Below is my build.gradle file:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'maven'
apply from: 'dependencies.gradle'
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
mavenLocal()
}
def tomcatHome = 'E:\\apache-tomcat-7.0.62'
//change the name of war because default it is mywar.1.0.0.war
war.archiveName "mywar.war"
//move the war into tomcat webapps folder
task deployToTomcat(type: Copy) {
from war
into "$tomcatHome/webapps"
}
You should split the module into two modules: the API JAR and the WAR. Depend on the API JAR from the WAR.

Categories