How to include shadows when publishing to Artifactory? (Gradle) - java

So for a little context: I have recently set up an Artifactory repository and I am new to working with Artifactory, everything I have been doing thus far has been from their user guide.
Now for the question: I would like to deploy a master plugin to Artifactory, but have it also include the shadowed dependencies on this using Gradle.
I have a general idea of deploying, and I have done so before, though I do not know how to deploy the code with the shadowed dependencies included and I am looking for some guidance that will allow me to do this.
I have included the parts of build.gradle that I believe is relevant for this:
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'sunace'
username = [REDACTED]
password = "${artifactory_password}"
}
defaults {
publishConfigs('archives', 'published')
properties {
all 'fun.sunace.master:MasterController:1.?:*#*', key2: 'val2', key3: 'val3'
}
publishBuildInfo = true
publishArtifacts = true
publishPom = true
publishIvy = false
publishForkCount = 8
}
}
clientConfig.setIncludeEnvVars(true)
clientConfig.info.addEnvironmentProperty('time.published',new java.util.Date().toString())
clientConfig.info.setBuildName('MasterController')
clientConfig.info.setBuildNumber('' + new Random(System.currentTimeMillis()).nextInt(20000))
clientConfig.timeout = 600
resolve {
repository {
repoKey = 'gradle-dev'
username = [REDACTED]
password = "${artifactory_password}"
maven = true
}
}
}
If you need anything else, just ask and I will amend the post with the requested assets.
Thanks to all those who help!

Related

Unable to use custom variables in Gradle extension

I'm using JIB (not super relevant) and I want to pass in variables from command line in my deployment script.
I append using -PinputTag=${DOCKER_TAG} -PbuildEnv=nonprod in my gradle command, which is cool. But when it's missing, I want that ternary to kick in.
I'm getting the error:
Could not get unknown property 'inputTag' for project ':webserver' of type org.gradle.api.Project.
def inputTag = inputTag ?: 'latest'
def buildEnv = buildEnv ?: 'nonprod'
jib {
container {
mainClass = 'com.example.hi'
}
to {
image = 'image/cool-image'
tags = ['latest', inputTag]
}
container {
creationTime = 'USE_CURRENT_TIMESTAMP'
ports = ['8080']
jvmFlags = ['-Dspring.profiles.active=' + buildEnv]
}
}
Found Solution
def inputTag = project.hasProperty('inputTag') ? project.property('inputTag') : 'latest'
def buildEnv = project.hasProperty('buildEnv') ? project.property('buildEnv') : 'nonprod'
This seems to be working, is this the best way?
How about this?
image = 'image/cool-image:' + (project.findProperty('inputTag') ?: 'latest')
Note jib.to.tags are additional tags. jib.to.image = 'image/cool-image' already implies image/cool-image:latest, so no need to duplicate latest in jib.to.tags.

Getting Play Framework works with Gradle and IntelliJ Idea

I'm trying to build my web application with Play Framework using Gradle as a build tool. My IDE is IntelliJ Idea.
I use Play with Java so I don't want to use SBT in my project. But it seems Play's not supported fully by IntelliJ Idea because the project structure is quite different. IntelliJ can't recognize it.
After a while googling, I found a solution, adding this script in build.gradle:
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus:[configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
But there is a problem, each time I open the project, I have to re-run idea task to make IntelliJ recognize the Play's structure.
Is there any way that's better than mine?
Thank you so much!
My Github example: https://github.com/TranNgocKhoa/play-gradle-intellij-example.
My build.gradle
plugins {
id 'play'
id 'idea'
}
def playVersion = "2.6.7"
def scalaVersion = System.getProperty("scala.binary.version", /* default = */ "2.11")
model {
components {
play {
platform play: playVersion, scala: scalaVersion, java: '1.8'
injectedRoutesGenerator = true
sources {
twirlTemplates {
defaultImports = TwirlImports.JAVA
}
}
}
}
}
def dependencyFor(String lib, String scalaVersion, String version) {
return lib + "_" + scalaVersion + ":" + version
}
dependencies {
play dependencyFor("com.typesafe.play:play-guice", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:play-logback", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:filters-helpers", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:play-java-jpa", scalaVersion, playVersion)
play "org.hibernate:hibernate-core:5.4.2.Final"
play "com.h2database:h2:1.4.197"
}
repositories {
jcenter()
maven {
name "lightbend-maven-releases"
url "https://repo.lightbend.com/lightbend/maven-release"
}
ivy {
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
}
}
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
I'm using Java 8, Gradle 5.4, Play 2.6.7
The below setup works now with some finessing required to get the rest of your dependencies up and running.
plugins {
id 'play'
id 'idea'
}
# replace with
plugins {
id 'idea'
id 'org.gradle.playframework' version '0.9'
}
The next step is to execute gradle idea and you should be able to just import the folder and intellij. If that is not the case go to Build tools -> Gradle and select use gradle

Gradle Plugin Duplicate Version Artifactory Search

I am trying to apply a plugin on a project that is a company specific findbugs plugin. In my Parent gradle project I have the following:
dependencies {
findbugs 'com.google.code.findbugs.findbugs:3.0.1'
findbugs configurations.findbugsPlugins.dependencies
// Here we specify the findbugsPlugins
findbugsPlugins 'com.company.common.company-findbugs-plugin:1.01'
}
task findbugs(type: FindBugs) {
classes = fileTree(project.rootDir.absolutePath).include("**/*.class");
source = fileTree(project.rootDir.absolutePath).include("**/*.java");
classpath = files()
pluginClasspath = project.configurations.findbugsPlugins
findbugs {
toolVersion = "3.0.1"
sourceSets = [sourceSets.main]
ignoreFailures = true
reportsDir = file("$project.buildDir/findbugsReports")
effort = "max"
reportLevel = "high"
includeFilter = file("$rootProject.projectDir/include.xml")
excludeFilter = file("$rootProject.projectDir/exclude.xml")
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
}
However, when I build the project, the build fails with an exception reporting:
Could not resolve all dependencies for configuration ':findbugsPlugins'.
> Could not find com.company.common.company-findbugs-plugin:1.01:.
Searched in the following locations:
http://artifactory.company.com:8081/artifactory/repo/com/company/common/company-findbugs-plugin/1.01//1.01-.pom
http://artifactory.company.com:8081/artifactory/repo/com/company/common/company-findbugs-plugin/1.01//1.01-.jar
Required by:
com.company.project:ProjectName1.0.4
Any reason why gradle is adding the version twice at the end of the path?
You have incorrectly defined the Gradle dependency, colon is missing between GroupId and ArtifactId:
'com.google.code.findbugs:findbugs:3.0.1'
and the same most likely applies for
'com.company.common:company-findbugs-plugin:1.01'

init.gradle read properties from command line

In my gradle script I've been able to successfully read properties like this:
def environment = hasProperty('env') ? env : 'dev'
Using this I can execute a build script like this:
gradlew clean assemble -Penv=prod
My issue comes in when I tried moving this to an init.gradle file. The file is recognized and I'm able to use other properties that I define in the script, however I'm not able to get any from the command line. How can I do this?
My init.gradle file:
allprojects {
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
project.ext['nexusDomainName'] = 'https://example.com/nexus'
project.ext['compileSdkVersion'] = 19
project.ext['buildToolsVersion'] = "19"
project.ext['minSdkVersion'] = 8
project.ext['targetSdkVersion'] = 19
project.ext['sourceCompatibility'] = '1.7'
project.ext['targetCompatibility'] = '1.7'
//hasProperty('release') is always false
project.ext['archiveType'] = hasProperty('release') ? '' : '-SNAPSHOT'
project.ext['archiveUrl'] = hasProperty('release') ? "$nexusDomainName/content/repositories/releases/" : "$nexusDomainName/content/repositories/snapshots/"
// This buildEnv property won't read either
project.ext['buildEnv'] = hasProperty('env') ? env : 'dev'
println "prepping for $buildEnv"
project.ext['archivesBaseNameSuffix'] = (project.ext['buildEnv'] == 'stage' || project.ext['buildEnv'] == 'dev') ? '-' + project.ext['buildEnv'] : ''
repositories {
mavenLocal()
maven {
credentials {
username 'username'
password 'password'
}
url "$nexusDomainName/content/groups/public/"
}
mavenCentral()
}
}
-P sets a project property, which isn't immediately available in an init script. (You can access projects and their properties from an init script, but that access will be deferred until the projects have been created.) However, using a system property (-D) should work.

Grails, Spring Security LDAP Plugin

I'm trying to get the LDAP plugin work. I only want a LDAP authentication against an Active Directory but it seems that I'm missing something.
Config
grails {
plugins {
springsecurity {
userLookup.userDomainClassName = 'de.ac.dmf.security.User'
userLookup.authorityJoinClassName = 'de.ac.dmf.security.UserRole'
authority.className = 'de.ac.dmf.security.Role'
ldap {
context.managerDn = 'CN=dmf Systemuser,CN=Users,DC=dmf,DC=local'
context.managerPassword = 'Password1'
context.server = 'ldap://192.168.100.133:389/'
authorities{
groupSearchBase ='OU=Groups'
groupSearchFilter = '(member={0})'
retrieveGroupRoles = false
retrieveDatabaseRoles = false
defaultRole = 'USER'
ignorePartialResultException = true
}
search{
base = 'CN=Users,DC=dmf,DC=local'
filter = '(sAMAccountName={0})'
searchSubtree = true
}
// mapper.userDetailsClass = 'user'
// auth.hideUserNotFoundExceptions = false
useRememberMe = false
}
}
}
}
On every login I just get this exception
2011-04-29 08:49:09,129 [http-8080-1] DEBUG springsecurity.RequestHolderAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E4, problem 2001 (NO_OBJECT), data 0, best match of:
'CN=Users,DC=dmf,DC=local'; remaining name 'CN=Users,DC=dmf,DC=local'
It doesn't matter which user from my AD I'm trying to authenticate. Is my configuration wrong?
I'm using
Grails 1.3.7
spring-security-core 1.1.2
spring-security-ldap 1.04
are you sure about your base configuration? Looks like OU=Users could work instead of CN=Users. Easiest way to figure this out is to use a tool like ad explorer (http://technet.microsoft.com/de-de/sysinternals/bb963907), connect to your AD, browse to a user and take a look at the path to the user...
Try using:
filter = '(&(sAMAccountName={0})(objectclass=user))'
That works on our AD.
You are missing the provider name list.
grails.plugins.springsecurity.providerNames = ['ldapAuthProvider',
'anonymousAuthenticationProvider',
'rememberMeAuthenticationProvider']

Categories

Resources