Intellij 2021 Cannot resolve symbol if it's from a custom maven repo? - amazon-web-services

I have a project where I'm using a dependency from a custom repository. This is what my build.gradle looks like (I have blurred out some dependencies for privacy):
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
group = 'com.myproject.projectx.sms'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven {
url "s3://myproject-maven-repo"
authentication {
awsIm(AwsImAuthentication)
}
}
}
dependencies {
implementation 'org.postgresql:postgresql'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.security:spring-security-core'
implementation 'com.myproject.top:secret-project:1.2' <------------ Gradle won't download this. why?
testImplementation 'org.spockframework:spock-spring:2.0-groovy-3.0'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'org.junit', module: 'junit'
}
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
test {
useJUnitPlatform()
}
There are red squiggly underlines when I hover over code that's using the top:secret-project dependencies. This used to work in old projects, but why can't intellij recognize it in this project? Also I can run the project successfully in ubuntu terminal with gradle bootRun. It's just intellij cannot recognize it. It also able to recognize spring, postgres, lombok & spock dependencies.
Cannot resolve symbol 'com.myproject.top.secret.TopSecretService'.
When click on build for gradle, I keep getting this error.
Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;)
I already exported the correct secret and keys in my .bashrc file. I also already configured ~/.aws/credentials. But I'm still getting the error above.

Am not really familiar with AwsImAuthentication nor the s3:// , but as it mentioned in the official doc that you need to add user/pass , or user/token as following
maven {
url 'https://my_domain-111122223333.d.codeartifact.region.amazonaws.com/maven/my_repo/'
credentials {
username "aws"
password System.env.CODEARTIFACT_AUTH_TOKEN
}
}
where CODEARTIFACT_AUTH_TOKEN is enviroment variable to store your password/session .
You can also use the gradle.properties to retrive the value , just make sure to replace System.env.CODEARTIFACT_AUTH_TOKEN with
project.findProperty.CODEARTIFACT_AUTH_TOKEN where CODEARTIFACT_AUTH_TOKEN is store the password/token in your gradle properties .

Related

Vendoring npm packages in deno

How does one vendor a npm package in deno?
import_map.json:
{
"imports": {
"lume/": "https://deno.land/x/lume#v1.12.1/",
}
}
Lume has some npm dependencies, like https://registry.npmjs.org/markdown-it/-/markdown-it-13.0.0.tgz.
deno.jsonc:
{
"importMap": "import_map.json",
}
dev_deps.ts:
export * as lume from "https://deno.land/x/lume#v1.12.1/mod.ts";
command:
$ deno vendor --force --unstable dev_deps.ts
# ...
Download https://registry.npmjs.org/markdown-it-attrs/-/markdown-it-attrs-4.1.3.tgz
# ...
thread 'main' panicked at 'Could not find local path
for npm:markdown-it-attrs#4.1.3', cli/tools/vendor/mappings.rs:138:11
I tried adding export * as ma from "npm:markdown-it-attrs"; to dev_depts.ts, but it did nothing.
I found the following issue on github.
Maybe this issue does have something to do with it.
I didn't find anything about how to resolve the problem in the official deno documentation and the lume documentation.
Unfortunately, currently you cannot use import_map in your Deno project if your goal is to publish a module that aims to be used in other applications, simply because you don't handle the way deno runtime will start.
From the application point of view, the deno run command cannot search every import_map configurations in your dependencies and handle them properly.
The import_map feature should be used only at end application level.
The fallback is to use by onvention a deps.ts source file to centralize all your dependencies.

Looking for documentation setup jest for unit test of admin plugin

my project was created with the swdc create-project ...
Is there a documentation, a tutorial or description for the right setup/configuration unit testing with JEST for custom plugin in administration?
This tutorial describes only how to write a test
But i think there must be a official setup documentation because of versions etc.
EDIT: a tutorial with code is now avialable
Using the suggested solution and execute the test, throws an configuration error:
● Test suite failed to run
Configuration error:
Could not locate module src/core/factory/module.factory mapped as:
undefined/src$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^src(.*)$/": "undefined/src$1"
},
"resolver": undefined
}
...
Cause of error:
process.env.ADMIN_PATH not setted but required in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/node_modules/#shopware-ag/jest-preset-sw6-admin/jest-preset.js
My solution:
set process.env.ADMIN_PATH in %Project%/custom/plugins/%MyPlugin%/src/Resources/app/administration/jest.config.js
// jest.config.js
...
const { join, resolve } = require('path');
process.env.ADMIN_PATH = resolve('../../../../../../../src/Administration/Resources/app/administration');
...
I think it is easiest to just copy and adapt from a plugin that already has jest tests set up. Look at the administration directory for SwagPayPal for example. Copy the dependency and script sections from their package.json. Also copy the entire jest.config.js. Then within the administration directory of your plugin you should be able to npm install followed by npm run unit or npm run unit-watch and it should find *.spec.js files within the test sub-directory.

aws 2.0 > step function > java.lang.NoClassDefFoundError: software/amazon/awssdk/core/runtime/transform/Unmarshaller

Getting this below error,
java.lang.NoClassDefFoundError: software/amazon/awssdk/core/runtime/transform/Unmarshaller
When executing the below code,
#Test
public void testStateFunction() {
SfnClient sfnClient = SfnClient.create();
System.out.println(sfnClient);
}
Have the below dependencies defined in build.gradle
dependencies {
implementation platform('software.amazon.awssdk:bom:2.17.29')
// implementation group: 'software.amazon.awssdk', name: 'core', version: '2.17.29', ext: 'pom'
implementation 'software.amazon.awssdk:core:2.17.29'
// implementation 'software.amazon.awssdk:aws-core:2.17.29'
// implementation 'software.amazon.awssdk:sdk-core:2.17.29'
implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:stepfunctions:2.0.0-preview-11'
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.10.0'
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.logging.log4j:log4j-api:2.13.0'
implementation 'org.apache.logging.log4j:log4j-core:2.13.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.0'
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
}
Tried many online searches, can't fix it yet.
From the InteliJ left menu Gradle libraries, when I try to expand
sdk-core, cannot find the class software/amazon/awssdk/core/runtime/transform/Unmarshaller in any jars.
Looks like you are trying to use AWS Step Functions using the AWS SDK for Java V2. To get this use working, you can follow this AWS end to end example that walks you through this use case and you will create the following workflow using AWS Step Functions.
Follow this document:
Create AWS serverless workflows by using the AWS SDK for Java
It uses Maven - but shows you the required dependencies (Once you get it working with Maven, then port the dependencies to gradle).
After further investigation found out that
The right latest dependency is
implementation 'software.amazon.awssdk:sfn:2.17.29'
And seems the below one which I tried initially was outdated and hence it did not worked with AWS 2.0 core jar /Unmarshaller which does not exist.
Reference: https://github.com/aws/aws-sdk-java-v2/issues/2094
Thanks
implementation 'software.amazon.awssdk:stepfunctions:2.0.0-preview-11'

Sonarqube gives 0% coverage on spring boot gradle project

So I am working with SonarQube and I keep getting stuck. My coverage is 0% while it should not be 0% (I made sure with an simple test that always should run correctly and covers at least one method).
I am reading a lot of different gradle.build files on the internet, but I can't find one that works for me.
Also I think the problem is that sonarqube can't find certain files, but I can't find a working directory of someone which I can compare with my own.
Gradle.build
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "org.sonarqube" version "3.0"
id 'jacoco'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '15'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
implementation('io.jsonwebtoken:jjwt:0.2')
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compile 'junit:junit:4.12'
implementation 'org.modelmapper:modelmapper:2.4.1'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.2.201908231537-r'
/**
* JUnit jupiter with mockito.
*/
testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.19.0'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.19.0'
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '5.1.6.RELEASE'
}
sonarqube{
properties{
property 'sonarjava.source', '1.8'
property 'sonar.java.coveragePlugin', 'jacoco'
}
}
test {
useJUnitPlatform()
}
This is the folder where my test reports are in (I think you will need this to help me):
The build directory:
The jacoco test directory
Can anyone help me with my problem? If you want to see directories or other files, just ask and add them to the post.
Thanks in advance!
you need to make sure jacoco runs before sonarqube, so add something like:
tasks["sonarqube"].dependsOn("jacocoTestReport")
Also, side note, compile is deprecated, so use implementation and testImplementation instead.
The answer was in a directory that I had not shown. My project was missing the Jacocoreportxml file. Once I added this with the gradle build jacocoreportxml command in my terminal it worked!

Angular 4 Unit Test cannot find name alert, confirm, event

Running ng test in angular-cli with Angular 4.0.0 gives errors like:
Cannot find name 'alert'
Cannot find name 'confirm'
Cannot find name 'Event'
This wasn't happening with Angular 2. Looks like something is missing here but what is it?
ng serve and build work fine.
In my case this was solved by adding "dom" to the "lib" array in tsconfig. I had a tsconfig.app.json that was used for building the app normally, and a tsconfig.spec.json that was just used for unit testing. This latter one was missing "dom".
{
"compilerOptions": {
...
"lib": [
"es2016",
"dom"
],
...
}
I was able to solve this by changing typings.d.ts according to latest cli documentation.
src/typings.d.ts:
Old:
/* SystemJS module definition */
declare var module: {
id: string;
};
New:
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}
To fix the issue I have generated a new project using latest #angular/cli and then compared and updated all of my tsconfg files to the current format.