I'm a beginner with gradle and I created an API for mysql and jedis. Now I want to send my project to a artifact repository . I searched how to do that and I fond the solution using "gradle publish". But when I run the command I have an error and I don't realy know why :/
build.gradle:
java
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'ronan' at '12/10/17 21:40' with Gradle 2.10
*/
group 'net.annorit24'
version '1.0-SNAPSHOT'
description 'API for Redis & Msyql'
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'idea'
sourceCompatibility = 1.8
repositories {
mavenCentral()
mavenLocal()
maven {
url
"https://repository.jboss.org/nexus/content/repositories/thirdparty-
releases"
}
}
configurations {
// configuration that holds jars to include in the jar
extraLibs
}
dependencies {
extraLibs "mysql:mysql-connector-java:5.1.37"
extraLibs group: 'redis.clients', name: 'jedis', version: '2.9.0'
configurations.compile.extendsFrom(configurations.extraLibs)
}
jar {
from {
configurations.extraLibs.collect { it.isDirectory() ? it :
zipTree(it) }
}
}
publishing {
repositories {
maven {
url 'https://mymavenrepo.com/repo/MIz0ZkX9Peab1z9j3ZM8/'
credentials {
username 'myUsername'
password 'myPassword'
}
}
}
publications {
maven(MavenPublication) {
from components.java
}
}
}
Logs : https://pastebin.com/CqDVixy6
If someone have an idea or can help me
Yours faithfully
Related
I am trying to accomplish a Java Spring course at Coursera and downloaded the project with this gradle file.
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
maven { url "https://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
war {
baseName = 'gs-convert-jar-to-war'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://maven.springframework.org/milestone" }
flatDir {
dirs 'lib'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-aop")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.data:spring-data-rest-webmvc")
compile("org.apache.httpcomponents:httpclient:4.5.6")
compile("org.hsqldb:hsqldb")
compile("com.google.guava:guava:17.0")
compile("org.apache.commons:commons-lang3:3.3.2")
compile("com.squareup.retrofit:retrofit:1.6.0")
compile("commons-io:commons-io:2.4")
compile("com.github.davidmarquis:fluent-interface-proxy:1.3.0")
compile(":mobilecloud.handin:1.0.0")
compile(":video.up.test:1.0.0")
compile(":autograder.handin:1.0.0")
compile(":autograder.spec:1.0.0")
testCompile("junit:junit")
}
Unfortunately, I have this error in IntelliJ Idea :
A problem occurred configuring root project 'mobile-cloud-asgn1'.
> Failed to notify project evaluation listener.
> org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
I am quite a newbie to Java and Gradle and never faced errors like this, so I have no idea how to fix it. Can anyone help me?
P.S. Repository with project template: https://github.com/juleswhite/mobile-cloud-asgn1
I have very simple java project, and I'm using gradle to build it.
And I have Linux RedHat server (without access to internet) but this server has access to internal nexus repository where all required dependencies present.
This is build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id 'com.github.jacobono.jaxb' version '1.3.5' // this is 14 line
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
buildscript {
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
allprojects {
buildscript {
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
}
}
Settings file settings.gradle:
include 'api'
project(":api").name = "api"
And this project has 1 submodule api filder.
api build.gradle file:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.jacobono.jaxb'
springBoot {
buildInfo()
}
group = 'com.example'
version = '1.0.0'
sourceCompatibility = 1.8
repositories {
maven { url "https://nexus.com.mysite/nexus/content/repositories/mirror/" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
}
springBoot {
mainClassName = 'com.example.TestApplication'
}
On my linux server I have:
- java 8
- gradle 4.5.1
- mvn 3.5.6
When I'm running gradle clean inside root folder of my project, after 5-10 mins I'm receiving error:
FAILURE: Build failed with an exception.
* Where:
Build file '/my-proj/build.gradle' line: 14
* What went wrong:
Plugin [id: 'com.github.jacobono.jaxb', version: '1.3.5'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.github.jacobono.jaxb:com.github.jacobono.jaxb.gradle.plugin:1.3.5')
Searched in the following repositories:
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10m 3s
And for some reason in this error there is no information about my nexus repository...I assuming that it even haven't tried this repository. And the question is why...?
I would be very happy of any help...maybe I made mistake in build.gradle file somewhere...
p.s. on my local pc(I have access to internet and to this repository everything works file)
Plugins by default resolved from Gradle Plugin Portal. If you want to resolve them from different sources, You should add configuration to settings.gradle file.
Example:
pluginManagement {
repositories {
maven {
url '../maven-repo'
}
gradlePluginPortal()
ivy {
url '../ivy-repo'
}
}
}
Check the docs for details.
As of now I have made a chatbot application by combining Java and Google Sheets using the Google API which requires me to use Gradle. So far I have only been able to run the program through Gradle using the terminal.
In my end result I want to be able to send this program to someone and they should be able to install it or run it as easy as possible without having to run it through the terminal.
I suspect that the person might need to download Gradle to run the file since it is needed for the Google API. So I think the best way to do this is to send a zip file (or something else) with the Gradle Installer and the java file and somehow make it install everything automatically. Is this possible?
This is how my build.gradle file looks like
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'SheetsQuickstart'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev516-1.23.0'
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.11.RELEASE')
}
jar {
doFirst {
manifest {
if (!configurations.compile.isEmpty()) {
attributes(
'Class-Path':configurations.compile.collect{it.toURI().toString()}.join(' '),
'Main-Class': 'SheetsQuickstart')
}
}
}
}
Assuming google sheets api is a dependency within gradle, cant you just build a jar file through gradle build then run the jar as an executable file?
build.gradle file example:
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
group = 'your.package.path.here'
version = '0.0.1-SNAPSHOT'
mainClassName = 'your.package.path.here.MainClassName'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring-core', version:'4.3.11.RELEASE')
}
repositories {
mavenCentral()
}
jar {
doFirst {
manifest {
if (!configurations.compile.isEmpty()) {
attributes(
'Class-Path':configurations.compile.collect{it.toURI().toString()}.join(' '),
'Main-Class': 'your.package.path.here.MainClassName')
}
}
}
Should be enough for a reg min build file, then add your dependencies.
I am using Spring boot gradle plugin version 1.5.1 RELEASE as shown below. The build fails at webProject complaining about missing property 'mainClass' and works only when I run 'webProject:build'. Is this the expected usage?
Edit: Updated the build script and removed 'spring-boot' plugin from allProjects. Had to add 'bootRepackage' in web project as it was failing at this step - with the same error. Adding the 'bootRepackage' didn't help.
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '1.5.1.RELEASE'
}
defaultTasks 'clean', 'build'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
allprojects {
apply plugin: 'java'
//apply plugin: 'org.springframework.boot' -- Commented out based on the answer
repositories {
mavenLocal()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
//all dependencies
}
}
project('aProject') {
dependencies {
compile(project(':bProject'))
}
}
project('webProject') {
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
war {
baseName = 'webProject'
version = '1.0.0-SNAPSHOT'
}
dependencies {
compile(project(':aproject'))
compile(project(':bProject'))
compile 'org.springframework.boot:spring-boot-starter-tomcat'
}
springBoot {
mainClass = 'com.abc.SomeApplication'
}
bootRepackage{
enabled = false
mainClass = 'com.abc.SomeApplication'
}
}
Do not use Spring Boot gradle plugin in main project, only in webProject sub-module.
I have a similar problem in a multi module Spring boot project.
When compiling module A which doesn't have a main class. The main class is in a different module (module B).
I add a plugin in that module A's build.gradle.
apply plugin: 'application'
mainClassName = "module B.ITS_MAIN_CLASS"
Then it works.
I'm using Gradle 3.2.1 (see the wrapper task). I have:
(1) This build.gradle script:
buildscript {
repositories {
mavenLocal()
}
apply from: 'gradle/buildscript.gradle', to: buildscript
}
plugins {
// ...
}
repositories {
//mavenLocal()
mavenCentral()
}
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
group 'io.shido'
version "${rootProject.version}"
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${spring_boot_version}")
}
}
dependencies {
apt "org.projectlombok:lombok:${lombok_version}"
compile 'org.springframework.boot:spring-boot-starter-actuator'
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
task wrapper(type: Wrapper) {
gradleVersion '3.2.1'
}
(2) This buildscript.gradle (located inside ${project.root}/gradle):
//
// Executed in the context of `buildscript { }`
repositories {
mavenLocal()
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:${spring_dependencies_management_version}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}")
}
(3) And a gradle.properties (located in ${project.root}):
#
# Global Project's Properties/Settings
rootProject.version = 0.1.0-SNAPSHOT
#
# Dependency Versions
spring_boot_version = 1.4.2.RELEASE
spring_dependencies_management_version = 0.6.0.RELEASE
The issue is that Gradle can't access the key/value pairs defined inside gradle.properties (for any script) anymore once I have this setup. So I can't access the values for spring_dependencies_management_version, spring_boot_version (for instance) in the .
Any clues?
NOTE: If I don't split up the Gradle configuration in different files, everything is fine, but that's not an option.