I have a gradle project in IntelliJ IDE in java.
my dependencies is like this:
apply plugin: 'maven-publish'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'com.intellij', name: 'annotations', version: '12.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile files('libs/someJar.jar')
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId group
artifactId 'mylibrary'
version version
from components.java
artifact sourceJar
}
}
}
the problem is when I publish my project in the published jar I didn't find somejar.jar so how can I publish it too.
I want all classes in someJar.jar be next to my main package.
Related
I've recently started using Avro and Kafka in my spring boot project. Now I've googled this and can't seem to find a straight answer.
When I build my war via my gradle build file, can I include the classes autogenerated from Avro schema?
Look at the war file when its exploded it doesnt seem to include those classes.
Here is my build.gradle file.
Many thanks for reading this question and if you have the time to help!
plugins {
id "org.springframework.boot" version "2.4.2"
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id "com.commercehub.gradle.plugin.avro" version "0.21.0"
id "idea"
}
group 'com.test.tge-auth-service'
version '1.0'
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
ext {
avroVersion = "1.10.1"
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://packages.confluent.io/maven/"
}
}
avro {
createSetters = true
fieldVisibility = "PRIVATE"
}
//apply plugin: "war"
dependencies {
// providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
compile group: 'co.elastic.logging', name: 'logback-ecs-encoder', version: '0.5.2'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.860'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.3.3.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '4.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.4.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.4.2'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.6.5'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
compile group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.passay', name: 'passay', version: '1.6.0'
compile group: 'com.google.guava', name: 'guava', version: '30.0-jre'
compile group: 'io.confluent', name: 'kafka-schema-registry-client', version: '6.0.0'
compile group: 'io.confluent', name: 'kafka-avro-serializer', version: '6.0.0'
compile group: 'io.confluent', name: 'monitoring-interceptors', version: '6.0.0'
compile(group: 'io.confluent', name: 'kafka-streams-avro-serde', version:'6.0.0') {
exclude(module: 'log4j-over-slf4j')
}
compile "org.apache.avro:avro:1.10.1"
implementation "org.apache.avro:avro:${avroVersion}"
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-web'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
jar {
manifest {
attributes(
'Main-Class': 'com.test.SpringBootPersistenceApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}
Ok so, for me what worked was a rebuild of the project in Intellij.
I have created a relatively new project with 4 modules inside one project (created with intelij). However, I have now got to the stage where I want to import one module (:domain) from another (app-updater). The issue I'm facing is when I do this from within intelij it gives me errors in the "Build: Sync" tab. This is strange since my module app-updater is able to reference to module domain when I add the line "compile project(':domain')" into build.gradle and when I remove the line I get issues with the class being missing so the build: sync seems to be working it's just running it from inside intelij seems to give an error saying "Project with path ':domain' could not be found in root project 'app-updater'." I have attached my gradle config below, hopefully I have given enough info but if not feel free to ask for more, thanks for any help.
Main project settings.gradle file
rootProject.name = 'rGuide'
include 'domain'
include 'service'
include 'app-updater'
include 'app-rest'
:domain build.gradle
group 'domain'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.9'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
app-updater build.gradle file
group 'app-updater'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
google()
maven {
url 'https://repo.spring.io/plugins-release/'
}
maven {
url 'https://repo.spring.io/milestone'
}
}
dependencies {
compile project(':domain')
// https://mvnrepository.com
compile group: 'net.ser1', name: 'gozirra-client', version: '0.4.1'
compile group: 'io.netty', name: 'netty-all', version: '4.1.36.Final'
compile group: 'io.projectreactor.netty', name: 'reactor-netty', version: '0.9.0.M2'
compile group: 'org.springframework.integration', name: 'spring-integration-stomp', version: '5.1.6.RELEASE'
compile group: 'org.springframework.integration', name: 'spring-integration-core', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '5.1.6.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.9'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
TLDR - Trying to import domain into app-updater within intelij, it "works fine" and seems to import domain however when I do this with the Build: sync tab in intelij it gives an error saying "Project with path ':domain' could not be found in root project 'app-updater'.". Thanks for any help!!
My byild.gradle file
Able to export jar with JAVA 8. when I configure to JAVA 11 exported jar doesn't contain external jars
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
}
configurations
{
all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12' //by both name and group
}
dependencies {
// 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'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
compile group: 'com.microsoft', name: 'sqljdbc4', version: '3.0'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
compile group: 'com.ibatis', name: 'ibatis2-common', version: '2.1.7.597'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.json', name: 'json', version: '20171018'
compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.13'
compile group: 'com.itextpdf.tool', name: 'xmlworker', version: '5.5.13'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.2'
}
add this below lines into your build.gradle
jar { manifest {attributes "Main-Class": "your main class" } from {configurations.compile.collect { it.isDirectory()? it : zipTree(it) } }
then do a clean/build,
the jar created in \build\libs folder is your runnable jar
I'm writing java console application using Spring Boot Jpa and MySQL connector. How I can easily exclude all unnecessary libs from my fat jar?
build.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
// mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.2.0'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'ca.cutterslade.analyze'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
mysqlVersion = '6.0.6'
hibernateVersion = '5.2.12.Final'
}
repositories {
mavenCentral()
}
dependencies {
// compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
// compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.12.Final'
// compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
// compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.5.9.RELEASE'
// compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.0.Final'
// compile group: 'org.springframework', name: 'spring-context', version: '4.3.13.RELEASE'
// compile group: 'org.springframework', name: 'spring-beans', version: '4.3.13.RELEASE'
// compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.9.RELEASE'
// compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// compile group: 'org.springframework', name: 'spring-tx', version: '2.5.4'
// compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.9.RELEASE'
// testCompile group: 'org.springframework.boot', name: 'spring-boot-test', version: '1.5.9.RELEASE'
// testCompile group: 'junit', name: 'junit', version: '4.12'
// testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.13.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: mysqlVersion
compile group: 'org.hibernate', name: 'hibernate-core', version: hibernateVersion
compile("org.springframework.boot:spring-boot-starter-data-jpa")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
jar {
baseName 'ReportGenerator'
version '1.0'
}
UPDATE
I have tried to use gradle-dependency-analyze and received the following result:
usedUndeclaredArtifacts:
- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
- org.springframework.boot:spring-boot:1.5.9.RELEASE
- org.springframework:spring-context:4.3.13.RELEASE
- org.springframework:spring-beans:4.3.13.RELEASE
- org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE
- org.slf4j:slf4j-api:1.7.25
- org.springframework:spring-tx:4.3.13.RELEASE
- org.springframework.data:spring-data-jpa:1.11.9.RELEASE
unusedDeclaredArtifacts:
- mysql:mysql-connector-java:6.0.6
- org.hibernate:hibernate-core:5.2.12.Final
- org.springframework.boot:spring-boot-starter-data-jpa:1.5.9.RELEASE
As you see unused libraries are marked all libraries in my gradle at the moment. And required librariesare marked only which are used in the scope of my classes in app but don't get me know what these required libraries depends on also. If I will put only these list of required dependencies in the gradle then I will get different initialization errors since some libraries are missed.
Couple of suggestions.
Use dependency:analyze on your project which will list the unused dependencies, which you can exclude or get rid of.
use the <scope> attribute for each and every dependency in your pom, which can greatly reduce your fat jar size. Provide correct scope parameters, like compile, test .....
When I try to run the gradle project from Idea I've an error
FAILURE: Build failed with an exception.
What went wrong: Task 'run Application' not found in root project 'app-search'.
Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. CREATE IMAGE BUILD FAILED
Total time: 0.153 secs Task 'run SearchApplication' not found in root
project 'app-search'.
Please how to solve it.?
This is the main part of my build.gradle
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'docker'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = 1.8
ext {
dropwizardVersion = '1.1.2'
mainClass = "com.jobservice.search.AppLauncher"
mapstructVersion = '1.1.0.Final'
}
mainClassName = mainClass
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
buildscript {
repositories { jcenter() }
dependencies {
classpath 'se.transmode.gradle:gradle-docker:1.2'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
}
}
// add logging into test stream
test {
testLogging.showStandardStreams = true
}
dependencies {
compile group: 'org.bouncycastle', name: 'bcprov-jdk16', version: '1.46'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.1'
compile group: 'org.slf4j', name: 'slf4j-ext', version: '1.7.25'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
compile 'com.google.inject:guice:3.0'
compile group: 'io.swagger', name: 'swagger-jersey2-jaxrs', version: '1.5.15'
compile group: 'io.swagger', name: 'swagger-annotations', version: '1.5.15'
compile group: 'com.hubspot.dropwizard', name: 'dropwizard-guice', version: '1.0.6.0'
compile group: 'org.liquibase', name: 'liquibase-core', version: '3.5.3'
compile (
'io.dropwizard:dropwizard-core:' + dropwizardVersion,
'io.dropwizard:dropwizard-hibernate:' + dropwizardVersion,
'org.postgresql:postgresql:9.4.1208.jre7',
'io.dropwizard:dropwizard-testing:' + dropwizardVersion
)
compile 'org.mapstruct:mapstruct-jdk8:' + mapstructVersion
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version: '2.0.0.0'
testCompile 'org.mockito:mockito-core:2.0.54-beta'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.194'
testCompile('org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:2.23.2') {
exclude group: 'javax.servlet', module: 'javax.servlet-api'
exclude group: 'junit', module: 'junit'
}
}
// Configure the shadow jar task
shadowJar {
classifier = 'dist'
baseName = 'jobs-search'
version = "1.0"
mergeServiceFiles()
manifest {
attributes 'Main-Class': mainClassName
}
version = ''
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
}