Gradle war plugin creation of directory structure - java

Using Eclipse I created a Gradle application which is a library, I want to create a web application and generate a .war file, so I added the war plugin:
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'war'
}
On the documentation https://docs.gradle.org/current/userguide/war_plugin.html it says that it creates a directory structure, but it doesn't create for me. Do I have to do something for it to create it or do I have to create it by hand?

Related

What is the purpose of apply maven plugin in build.gradle?

I keep seeing apply plugin: 'maven' in build.gradle files for Java projects. What is the purpose of adding a Maven plugin? I can't seem to find the plugin when querying for it on plugins.gradle.org.
Why don't you just google it?
http://sorcersoft.org/project/site/gradle/userguide/maven_plugin.html
"The Maven plugin adds support for deploying artifacts to Maven repositories."

Apply gradle custom module plugin

I created a plugin for gradle with java.I want to test it.
so, I created a another gradle project add I added my plugin as a module.
Now , How can I apply my module as a plugin in build.gradle file ?
My project structure
My plugin
version '1.0.0'
id = 'com.hello.first.plugin'
implementationClass = 'com.hello.first.plugin'
Here I saw for applying jar as a plugin in gradle : ANSWER.
How can I add module as a plugin in build.gradle ?
You need to make it a standalone project and publish it, at least to mavenLocal().
Then just add mavenLocal() into buildscript.dependencies and it should resolve.
A local flatDir repository should work, too.

Add gradle dependencies(build.gradle) in .aar file Android

I am having an android library project which is using third party libraries. I have created it's .aar file and imported the .aar file in a different project. Classes and resources are imported but the gradle libraries are not imported. I don't want to mention those dependencies again in the project.
Is there any way to import that project with .aar file or something else which include build.gradle or dependencies.
If you are including this library in dependencies block then try to use api instead of implementation.
AAR file does not include external dependencies which are mention in app/build.gradle so instead of adding it directly we upload to local maven and integrate it.
To upload it in your local maven you can add the following function in app/build.gradle
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost" + System.getenv("HOME") + "/.m2/repository")
pom.version = '1.0-SNAPSHOT'
pom.groupId = 'your.package'
pom.artifactId = 'sdk-name'
}
}
}
You can change the pom version, groupId and artifactId according to how you want to use it.
If this process is completed you can integrate the library.
In the app/build.gradle of the project in which you want to add the
library specify the path.
implementation 'your.package:sdk-name:1.0-SNAPSHOT'
In the project/build.gradle add the following
allprojects{
...
mavenLocal()
}
This will search for the library in the local machine.
If still, you get some error try to invalidate caches and restart the android-studio from the File Menu.

How to generate .java and .class files of mapstruct mappers by saving a java file in Eclipse instead of building it with gradle

I'm working on a java 8 gradle project in Eclipse (2019-09) including lombok. I would love to use mapstruct for converting models into dto and vice versa.
Mapstruct works great.
Problem:
I have some trouble that Eclipse creates and compiles the mapper implementation when saving the file.
The XYMapperImpl.java/class files are only created when using ./gradlew classes.
Building it with gradle is not really an option because it takes some time and does not really work in my workflow. I need to have the .class file at the end to mount the whole /bin folder into a docker container.
I'm using the Eclipse MapStruct plugin, however this is only for Code Completion and Quick Fixes but not for generating class files.
I've done some research:
How to get Eclipse to generate MapStruct Mappers using Gradle or How to properly integrate MapStruct with Eclipse? (Including Lombok java agent) and some others without any success.
Maybe I missed something?
My build.gradle file:
plugins {
id 'java'
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt" version "0.21"
}
apply plugin: "java"
apply plugin: "net.ltgt.apt-eclipse"
apply plugin: "net.ltgt.apt"
repositories {
mavenCentral()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
compile "org.mapstruct:mapstruct-jdk8:1.3.0.Final"
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final" //Must be defined before the lombok annotationProcessor
annotationProcessor 'org.projectlombok:lombok:1.18.6'
}
I've created a simple demo project as an example.

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