I'm working on a java project where bazel is being used. I'm looking to add tink java lib in bazel but looks like com_github_google_tink is not a valid package name.
java_library(
name = "testlib",
srcs = glob(["*.java"]),
deps = [
"#com_github_google_tink",
],
visibility = ["//visibility:public"],
)```
I already referred this article https://developers.google.com/tink/install-tink but it only talks about adding java deps in maven. Can someone help ?
Are you using rules_jvm_external to get the tink dependency?
https://github.com/bazelbuild/rules_jvm_external
If not, you might try adding this or similar to your WORKSPACE file:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_JVM_EXTERNAL_TAG = "4.2"
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("#rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()
load("#rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()
load("#rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.google.crypto.tink:tink:1.6.1",
],
repositories = [
"https://repo1.maven.org/maven2",
],
)
Then you can use the tink dependency from maven in your BUILD / BUILD.bazel file like this:
java_library(
name = "testlib",
srcs = glob(["*.java"]),
deps = [
"#maven//:com_google_crypto_tink_tink",
],
visibility = ["//visibility:public"],
)
Related
I have a lambda function that is written in nodejs (using AWS nodejs SDK) and we are using gradle (build.gradle) to package and deploy that to AWS.
Deployment is working fine but when I am trying to update tags on this Lambda and redeploying then the new tags are not being applied to that function.
So if I am deploying Lambda using build.gradle first time with TAG A then its working fine (By first time I mean when I am creating a new Lambda) and tag is being applied and I can see that on AWS Console. But when I am re-deploying it again by adding another tag "TAG B" then the new tag is not being applied and it is not updating the existing Lambda tags. Any idea or suggestion what I am doing wrong? Thanks
Below is the section of build.gradle file where I am applying the tags for Lambda.
createOrUpdateFunction {
handler = 'index.handler'
role = cfo.DataDigestContentSearchLambdaIamRoleArn
runtime = 'python3.7'
timeout = 10
tags = [
tagA: 'data-team',
tagB: 'someValue'
]
Here is the complete build.gradle file
import com.amazonaws.services.lambda.model.TagResourceRequest
apply plugin: 'com.abc.gradle.nodejs.yarn'
apply plugin: 'com.abc.gradle.aws.lambda.deployment'
apply from: rootProject.file('gradle/yarn-webpacked-lambda.gradle')
nodejs {
packaging {
name = '#abc/data-fulfillment-facebook-lambda'
dependency project(':core:js')
dependency project(':platforms:facebook:js:core')
dependency '#abc/data-ingest-api', abc_INGEST_SEMVER
dependency '#abc/data-ingest-core', abc_INGEST_SEMVER
dependency 'aws-sdk', AWS_SEMVER
}
}
webpackPackageJson.dependencies << ['fb': FB_SEMVER]
lambdaRepository {
artifactName = 'data-fulfillment-facebook'
}
lambda {
functionName = "${config.aws.target.envPrefix}-${lambdaRepository.artifactName}"
}
def cfo = cloudformation.outputs as Map<String, String>
createOrUpdateFunction {
handler = 'index.handler'
role = cfo.DataFulfillmentFacebookLambdaIamRoleArn
runtime = 'nodejs12.x'
memorySize = 256
timeout = 30
tags = [
team: 'data-team',
name: 'someName'
]
environmentAsMap << [
FACEBOOK_LEDGER_TABLE_NAME: cfo.DataFulfillmentLedgerTableName,
INSTAGRAM_DISCOVERY_TOKEN_SECRET: cfo.DataFulfillmentInstagramDiscoveryTokenSecretName
]
}
task registerTaskProcessor(type: RegisterTaskProcessorTask) {
client 'target'
tableName = cfo.DataFulfillmentTaskProcessorRegistryV2TableName
entryName = 'facebook'
rules << [regex: ['^facebook', [var: 'task.type']]]
type = 'lambda-dispatch'
params << [functionName: lambda.functionName, qualifier: 'live']
}
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!
I need to do a security scan for my application. I have wrote this code to download all the dependent JARs
barvaz := {
buildStandalone.value
// Define the paths to the ".ivy2" in the current-working-directory (localIvy) and in the
user's home
val localIvy = (baseDirectory in publishLocal).value / ".ivy2"
val projectBoot = (baseDirectory in publishLocal).value / "project/boot"
// Package everything in target/standalone.zip so it could easily be copied around
val ivy2Files = (localIvy ** "*.jar").get.map(_.getPath.replaceAll(".*\\.ivy2", ".ivy2"))
val projectFiles = (projectBoot ** "*.jar").get.map(_.getPath.replaceAll(".*boot", "project/boot"))
val jarNames = (ivy2Files ++ projectFiles).map(_.replaceAll("\\\\", "/")) //Seq("sbt-launch.jar") ++
Packaging.downloadLibSourcesAndBins((resourceDirectory in Compile).value / "barvaz", jarNames)
val downloadedJars = ((target.value / "barvaz") ** "*.jar").get.map(f => f -> f.getPath.replaceFirst(".*barvaz", ""))
IO.zip(downloadedJars, new File(s"target/barvaz-${version.value}.zip"))
"Done"
}
however I have now duplicates of JARs from different versions , for example jettey from version 4.0.0 and 4.0.1 and of course some testing JARs
How can I inspect which JARs are actually loaded?
You can try show fullClasspath in sbt.
Edit:
If you want a pretty text output (perhaps to feed into some other programs), you can try consoleProject and then in the scala repl, evaluate: println(fullClasspath.in(Compile).eval.map(_.data).mkString("\n")).
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'
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.