Trouble running ./gradlew build - javascript

Gradle cannot build to an unknown error
I attempted to build an application by typing the command ./gradelw build on the terminal. It throws an error message that Build file '/home/muhammad/bootcamp-projects/java-app/build.gradle'
line: 28
A problem occurred evaluating root project 'my-app'.
Could not get unknown property 'repoUser' for root project 'my-app' of type org.gradle.api.Project.
this is the code :
`plugins {
id 'java'
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
group 'com.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact("build/libs/my-app-$version"+".jar") {
extension 'jar'
}}
}
}
repositories {
maven {
name 'nexus'
url "http://159.65.23.158:8081/repository/maven-snapshots/"
credentials {
username project.repoUser
password project.repoPassword
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '5.2'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
repositories {
maven {
name 'nexus'
url "http://159.65.23.158:8081/repository/maven-snapshots/
credentials {
username project.repoUser
password project.repoPassword `
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'net.logstash.logback', name: 'logstash-logb
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
`
please can you help me

You do not say where you defined repoUser and repoPassword .
If these are defined as environment variables, then you can use:
username = System.getenv('repoUser')
password = System.getenv('repoPassword')

Related

How do I access environment variables in Strapi v4?

Strapi Version: 4.3.0
Operating System: Ubuntu 20.04
Database: SQLite
Node Version: 16.16
NPM Version: 8.11.0
Yarn Version: 1.22.19
I have created Preview button for an article collection type. I'm using the Strapi blog template. I managed to make the Preview button appear in the Content Manager. I hard coded the link to be opened when you click the Preview button and it works. Now, I want the plugin to use a link with environment variables instead of a hard coded link. I don't know how I can access the environment variables in the source code for the plugin.
My objective:
I want to replace
href={`http://localhost:3000?secret=abc&slug=${initialData.slug}`}
with
href={${CLIENT_FRONTEND_URL}?secret=${CLIENT_SECRET}&slug=${initialData.slug}`}
in ./src/plugins/previewbtn/admin/src/components/PreviewLink/index.js
where CLIENT_FRONTEND_URL and CLIENT_SECRET are environment variables declared like so in .env:
CLIENT_FRONTEND_URL=http://localhost:3000
CLIENT_PREVIEW_SECRET=abc
Here's a rundown of the code I used:
First, I created a strapi app using the blog template, then created a plugin.
// Create strapi app named backend with a blog template
$ yarn create strapi-app backend --quickstart --template #strapi/template-blog#1.0.0 blog && cd backend
// Create plugin
$ yarn strapi generate
Next, I created a PreviewLink file to provide a link for the Preview button
// ./src/plugins/previewbtn/admin/src/components/PreviewLink/index.js
import React from 'react';
import { useCMEditViewDataManager } from '#strapi/helper-plugin';
import Eye from '#strapi/icons/Eye';
import { LinkButton } from '#strapi/design-system/LinkButton';
const PreviewLink = () => {
const {initialData} = useCMEditViewDataManager();
if (!initialData.slug) {
return null;
}
return (
<LinkButton
size="S"
startIcon={<Eye/>}
style={{width: '100%'}}
href={`http://localhost:3000?secret=abc&slug=${initialData.slug}`}
variant="secondary"
target="_blank"
rel="noopener noreferrer"
title="page preview"
>Preview
</LinkButton>
);
};
export default PreviewLink;
Then I edited this pregenerated file in the bootstrap(app) { ... } section only
// ./src/plugins/previewbtn/admin/src/index.js
import { prefixPluginTranslations } from '#strapi/helper-plugin';
import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import Initializer from './components/Initializer';
import PreviewLink from './components/PreviewLink';
import PluginIcon from './components/PluginIcon';
const name = pluginPkg.strapi.name;
export default {
register(app) {
app.addMenuLink({
to: `/plugins/${pluginId}`,
icon: PluginIcon,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: name,
},
Component: async () => {
const component = await import(/* webpackChunkName: "[request]" */ './pages/App');
return component;
},
permissions: [
// Uncomment to set the permissions of the plugin here
// {
// action: '', // the action name should be plugin::plugin-name.actionType
// subject: null,
// },
],
});
app.registerPlugin({
id: pluginId,
initializer: Initializer,
isReady: false,
name,
});
},
bootstrap(app) {
app.injectContentManagerComponent('editView', 'right-links', {
name: 'preview-link',
Component: PreviewLink
});
},
async registerTrads({ locales }) {
const importedTrads = await Promise.all(
locales.map(locale => {
return import(
/* webpackChunkName: "translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);
return Promise.resolve(importedTrads);
},
};
And lastly this created this file to enable the plugin Reference
// ./config/plugins.js
module.exports = {
// ...
'preview-btn': {
enabled: true,
resolve: './src/plugins/previewbtn' // path to plugin folder
},
// ...
}
I solved this by adding a custom webpack configuration to enable Strapi's admin frontend to access the environment variables as global variables.
I renamed ./src/admin/webpack.example.config.js to ./src/admin/webpack.config.js. Refer to the v4 code migration: Updating the webpack configuration from the Official Strapi v4 Documentation.
I then inserted the following code, with help from Official webpack docs: DefinePlugin | webpack :
// ./src/admin/webpack.config.js
'use strict';
/* eslint-disable no-unused-vars */
module.exports = (config, webpack) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack config
// Important: return the modified config
config.plugins.push(
new webpack.DefinePlugin({
CLIENT_FRONTEND_URL: JSON.stringify(process.env.CLIENT_FRONTEND_URL),
CLIENT_PREVIEW_SECRET: JSON.stringify(process.env.CLIENT_PREVIEW_SECRET),
})
)
return config;
};
I rebuilt my app afterwards and it worked.
You shouldn't have to change the webpack config just find .env file in the root directory
add
AWS_ACCESS_KEY_ID = your key here
then just import by
accessKeyId: env('AWS_ACCESS_KEY_ID')

H88 Error: Invalid account: #0 for network - Expected string, received undefined

This is my hardhat.config.js -
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: [process.env.pk]
},
// polygon: {
// url: "https://polygon-rpc.com/",
// accounts: [process.env.pk]
// }
}
};
When running npx hardhat test the following error appears:
**Error HH8: There's one or more errors in your config file:
Invalid account: #0 for network: mumbai - Expected string, received undefined**`
Seems I have a couple of errors with my hardhat.config.js file but can't locate. I am using Nader Dabit's full-stack-web3 tutorial for full stack web3 development.
Correct:
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: process.env.pk
Incorrect:
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: [process.env.pk] <-- remove the array
The issue here is with how the accounts datatype is defined.
accounts is of type HardhatNetworkAccountsUserConfig. It contains an array of account objects, which is of type HardhatNetworkAccountUserConfig.
(Notice how accounts has 'Accounts' in this type name while account has 'Account')
Now, this account is an object that contains two values: private key and balance
. You can read more about it here.
This is enough background knowledge. Let's jump into the code.
First, define accounts as such:
import {HardhatNetworkAccountsUserConfig} from "hardhat/types/config";
import { ethers } from "ethers";
const accounts: HardhatNetworkAccountsUserConfig = [
{
privateKey: process.env.pk!,
balance: ethers.utils.parseEther('10000').toString()
}
]
Notice the '!' after process.env.pk. The reason for its addition is well explained in this StackOverflow thread.
Now, define the config using the code below:
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts
// polygon: {
// url: "https://polygon-rpc.com/",
// accounts
// }
}
};
npx hardhat node should work fine now.
I had the same issue and solved it a different way because it was still saying invalid account (although I was on the goerli testnet). I figured out you need to put a 0x in front of the private key so I added an OR statement to the PRIVATE_KEY variable as follows:
const PRIVATE_KEY =
process.env.PRIVATE_KEY ||
"0xfake1private2key3fake4private5key6fake7private8key"
and then used that variable as follows:
networks: {
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY],
},

recoverTypedSignature function on #metamask/eth-sig-util is not working

It seems that every that the updated recoverTypedSignature function on #metamask/eth-sig-util is not working properly. As soon as I add it into the project, it gives out an error.
The error is:
bundle.js:6306 Uncaught ReferenceError: Buffer is not defined at Object../node_modules/#metamask/eth-sig-util/node_modules/ethereumjs-util/dist/secp256k1v3-lib/der.js (bundle.js:6306:40) at Object.options.factory (bundle.js:84170:31) at webpack_require (bundle.js:83608:33) at fn (bundle.js:83841:21) at Object../node_modules/#metamask/eth-sig-util/node_modules/ethereumjs-util/dist/secp256k1v3-adapter.js (bundle.js:5932:11) at Object.options.factory (bundle.js:84170:31) at webpack_require (bundle.js:83608:33) at fn (bundle.js:83841:21) at Object../node_modules/#metamask/eth-sig-util/node_modules/ethereumjs-util/dist/index.js (bundle.js:5724:17) at Object.options.factory (bundle.js:84170:31)
The code is:
import { SignTypedDataVersion, recoverTypedSignature } from '#metamask/eth-sig-util';
const Request_Signature = (props: any) => {
// Step 2: Once user has authorized the use of its crypto wallet a signature can
// be requested
async function sign_TypedDataV4() {
const msgParamsOg = {
domain: {
// Defining the chain: 1 - Ethereum Main Net
chainId: 1,
// Friendly name
name: "Initial Example Contract",
// Additional way of verifying contract to make sure you are establishing contracts with the proper entity
verifyingContract: "this",
// Just let's you know the latest version. Definitely make sure the field name is correct.
version: "1",
},
// Defining the message signing data content.
message: {
Request: "Please complete your authentication by signing this",
username: "test_user",
},
// Refers to the keys of the *types* object below.
primaryType: "LogIn",
types: {
EIP712Domain: [
{
name: "name",
type: "string",
},
{
name: "version",
type: "string",
},
{
name: "chainId",
type: "uint256",
},
{
name: "verifyingContract",
type: "address",
},
],
// Refer to PrimaryType
LogIn: [
{
name: "username",
type: "string",
},
],
},
};
let msgParams = JSON.stringify(msgParamsOg);
let account = props.account;
var params = [account, msgParams];
var method = "eth_signTypedData_v4";
console.log('User Address:' + account);
(window as any).ethereum.sendAsync(
{
method,
params,
account,
},
async function (err: Error, result: any) {
if (err) return console.dir(err);
if (result.error) {
alert(result.error.message);
return console.error("ERROR", result);
}
//console.log('TYPED SIGNED:' + JSON.stringify(result.result));
let signature = result.result;
const restored = recoverTypedSignature({
data: msgParamsOg as any,
signature,
version: SignTypedDataVersion.V4,
});
console.log(restored);
}
);
}
return (
<div>
<button
className='btn_main'
type="button"
onClick={async (e) => {
e.preventDefault();
sign_TypedDataV4();
}}
>
Sign Now
</button>
</div>
)
};
export default Request_Signature;
If you are using react, I don't know the exact fix but this is a workaround:
downgrade react-scripts to version 4.0.3
In my case I needed to do the following also:
In package.json use react-script 4.0.3
Remove package-lock.json
remove node_modules folder
run npm install
After all this everything seems to be working fine.
I had to use webpack (https://webpack.js.org/) with Babel (https://babeljs.io/docs/en/babel-preset-react) to solve this. I as well had to install Buffer (https://www.npmjs.com/package/buffer) and stream-browserify (https://www.npmjs.com/package/stream-browserify)
This resolved the problem

Allure report on Jenkins producing NAN% and null report URL

Allure report on Jenkins producing NAN% and null report URL. I have a pipeline below and it is generating the report on the URL /null/. It was working fine before my added ${env.HOME} in my directories. But now it does not work
pipeline {
agent {
label {
label ""
customWorkspace "${env.HOME}/test"
}
}
tools {nodejs "node"}
stages {
stage('Checkout App') {
steps {
dir("${env.HOME}/app") {
echo "Building.."
sh 'git pull'
}
// build shopfloor app
dir("${env.HOME}/app") {
sh "/${env.HOME}/test/App.sh"
}
}
}
}
post('Publish Report') {
always {
script {
allure([
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'target/allure_results']]
])
}
}
}
}
It says allure report generated on:
allure-results does not exists
Report successfully generated to /Users/john/.jenkins/null/test/allure-report
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
You are creating a directory with dir("${env.HOME}/app"){...} inside the workspace. For that reason, allure didn't find the results, you could do something like this:
Check if the path is correct, but this will be an example:
results: [[path: '$WORKSPACE/${env.HOME}/app/target/allure_results']]

Grunt-scaffold after() function access to prompt answers

The docs for the NPM package grunt-scaffold lacked any information really on its after() property/function.. I have a grunt file which creates a new directory for a new script and copies boilerplate files into it from the designated template folder.. The desire is to finish the grunt scaffold:new_script command and have it log out the location of the newly generated folder.
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
scaffold: {
new_script: {
options: {
questions: [{
name: 'script_name',
type: 'input',
message: 'Script name, catterpillar_case?(e.g. \'new_script\'):'
}],
template: {
"scripts/etl_template/": "scripts/{{script_name}}/",
},
after: function(){
console.log("New script generated in new folder scripts/{{script_name}}")
}
}
}
}
});
grunt.loadNpmTasks('grunt-scaffold');
grunt.registerTask('default', ['scaffold']);
};
However, the ouput is
-bash-4.1$ grunt scaffold:new_script
Running "scaffold:new_script" (scaffold) task
? Script name, catterpillar_case?(e.g. 'new_script'): test_grunt
New script generated in new folder scripts/{{script_name}}
Done.
This did not do the string replacing as it did when it created the scripts/test_grunt folder! As you can see the documentation almost doesn't exist for that after() functionality, and I'm wondering if I can use javascript"system argume
An example was not given in the documentation for the after() function, but if you use the same result parameter as in the example given for filter(), you can access the answer values via their names.
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
scaffold: {
new_script: {
options: {
questions: [{
name: 'script_name',
type: 'input',
message: 'Script name, catterpillar_case?(e.g. \'new_script\'):'
}],
template: {
"scripts/etl_template/": "scripts/{{script_name}}/",
},
after: function(result){
console.log("New script generated in new folder scripts/" + result.script_name)
}
}
}
}
});
grunt.loadNpmTasks('grunt-scaffold');
grunt.registerTask('default', ['scaffold']);
};
Output
-bash-4.1$ grunt scaffold:new_script
Running "scaffold:new_script" (scaffold) task
? Script name, catterpillar_case?(e.g. 'new_script'): test_grunt
New script generated in new folder scripts/test_grunt
Done.

Categories

Resources