project.assets.json file references 2 different versions of a package for the same framework - nuget-package

I have a project that is multi-targeted net472 & net6.0-windows. For net6.0-windows there is a transient package reference with 2 different versions.
4.0.0
MyProject -> SSH.NET/2016.1.0 -> System.Net.NameResolution/4.0.0
4.3.0
MyProject -> Rebex.Elliptic.Ed25519/1.2.1 -> NETStandard.Library/1.6.1 -> runtime.win.System.Net.Sockets/4.3.0 -> System.Net.NameResolution/4.3.0
Now project.assets.json states all the target frameworks and it's dependencies. But for this project it states 2 different versions for the same framework.
"targets": {
".NETFramework,Version=v4.7.2": { //not relevant },
".NETFramework,Version=v4.7.2/win7-x64": { //not relevant },
"net6.0-windows7.0": {
System.Net.NameResolution/4.0.0
},
"net6.0-windows7.0/win7-x64": {
System.Net.NameResolution/4.3.0
}
In our team we have some custom build tools, that ran into this and failed, and I want to understand why did it happen, and why only for this project since we have multiple multi-targeted projects. How is this project.assets.json generated? Why did it state 2 different version for the same framework?

Related

ParserError while compiling solidity code

I am new to solidity.
This is my 1st simple project
when I do node compile.js & I am getting following error:
My Error :
{
contracts: {},
errors: [
":7:16: ParserError: Expected identifier, got 'LParen'\n" +
' constructor(string initialMessage) public{\r\n' +
' ^\n'
],
sourceList: [ '' ],
sources: {}
}
my compile.js
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inboxPath = path.resolve(__dirname,'contracts','Inbox.sol');
const source = fs.readFileSync(inboxPath,'utf8');
console.log(solc.compile(source,1));
my Inbox.sol
pragma solidity ^0.4.17;
contract Inbox {
string public message;
constructor(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public{
message = newMessage;
}
}
I'm not sure why you are attempting to compile your smart contract natively using node. That is a fairly cumbersome approach (although it can be done, albeit with exponentially more work on your part), especially when tools already exist for this purpose.
The prefered method would be to use a tool such as the most recent build of truffle (which is a CLI tool available as a NodeJS package via NPM for compiling, deploying and testing smart contracts), instead of using NodeJS to compile.
Simply install truffle as a global package from a console using:
npm install -g truffle
Then navigate to your project root directory and run:
truffle init
This will generate a barebone project structure with everything that is required (such as directories for contracts and migrations).
After the project has been init'ed, open the truffle-config.js file and add the configurations required for your project:
module.exports = {
networks: {
//Configuration for localhost private dev network for testing code
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" //Match any network id
}
//Connecting to the main, live ethereum network requires different config
//and should NOT be used for development purposes.
//Only after your contracts have been thoroughly tested and audited should you deploy a production ready project to the main net.
},
compilers: {
solc: {
version: "0.6.2"
}
}
};
You can specify whichever compiler version suites your needs, however, most contracts now a days should target version 0.6.0 and up for the most recent features.
Learn more about customizing Truffle's configuration here!
Now, this allows you to specify both the network to deploy to and the specific solidity compiler (which truffle will automatically download the correct version if it does not already exist on your system) to run when compiling your project.
After this is complete, your contracts can be compiled easily using:
truffle compile --all --network development
Note that the argument for --network must match an entry in truffle-config.js's networks object (although just for compiling, it should not be necessary to specify a network, only for deployment).
Then there you go! You have compiled your first smart contract.
However, there is one caveat.
At this point you do not have a local test network to deploy to.
When deploying the contract, it's important to be aware to not deploy untested code to the live main network until it has been tested and audited.
Since any changes to the blockchain are permanent, deploying buggy contracts to the live blockchain can't be undone and any bugs can and will be exploited by malicious agents indefinitely.
To solve this issue, the trufflesuite team also provides ganache-cli (alongside various other helpful tools) for running a private test network on localhost. This package is also available via NPM however, that goes beyond the scope of this answer and your question.
Hope that helps you get started, best of luck!
The problem you are facing is a result of the compiler version. with solidity compiler version 0.4.17 all you need to do is replace the constructor keyword with the name of the contract i.e implicitly creating the constructor function. That should do the trick and yes your code editor will most likely complain especially if you have linting enabled but your codes will still run

Exclude a specific package from react metro bundler when building

I have a library that requires:
rnkata.js when running in react native
webkata.js when running in a browser
nodekata.js when running in node
This hack works OK as long as I'm only targeting node/web:
if (getEnv() == "node") {
eval('require')('nodekata')
} else {
require('webkata')
}
But once I started targeting mobile, metro bundler would complain "webkata not available":
if (getEnv() == "node") {
eval('require')('nodekata')
} else if (getEnv() == "mobile") {
require('rnkata')
} else {
require('webkata')
}
Obviously, I can't use the same eval hack - or I break either webpack or RN. Is there some documentation on how to manage this situation? IE: how can i suppress bundling or interpreting of a 'require' call by platform.
Is there a "suppress by module name" feature? Or some other way to have a platform-specific module?
Metro recently added support for Optional imports. It should be available in React Native v0.63.0. See this issue and this PR for more details.
You could also consider doing naming the files to show which platforms they support. For example:
index.js - web version
index.native.js - android & ios only version
index.android.js - android version
index.ios.js - ios version

writing nodejs applications in kotlin with intellij idea ce

I am trying to develop a Nodejs application using Kotlin 1.3.11 using the IntelliJ IDEA CE development environment. Unfortunately I haven't made any progress towards a running application. To ensure everything is setup correctly I want to print out a simple "hello world".
I searched for articles or tutorials about the topic but I didn't find much about bringing those three together (Kotlin, IntelliJ, Nodejs). The most specific ones which I found are:
a medium post and another post.
As far as I (believe to) know, there are three major steps:
calling initializing the node app via npm and using npm to install the node dependencies like kotlin and expressjs
creating a build.gradle to define other dependencies and tasks
creating an IntelliJ IDEA project
I tried to perform the steps in different orders but I never came to a running application. Also I searched in IntelliJ's documentation but the Nodejs integration isn't a feature of the free community edition. There isn't a description how to make Kotlin and Nodejs work together too.
Has anyone here successfully tried to do that (or failed and knows why it is not going to work)? Do I have to use another IDE or to write my own build tools/toolchain?
Sincerely J.
I haven't done this in IDEA CE, but theoretically, this should work.
Prerequisites: You have node installed, you can execute gradle tasks
This is a Minimum Configuration, There is a comprehensive one. Add a comment if intrested for that
Step 1:Create a new Kotlin/JS project (with gradle) and make sure that your gradle build file looks like this
group 'node-example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
compileKotlin2Js.kotlinOptions {
moduleKind = "commonjs"
outputFile = "node/index.js"
}
task npmInit(type: Exec) {
commandLine "npm", "init", "-y"
}
task npmInstall(type: Exec) {
commandLine "npm", "install", "kotlin", "express", "--save"
}
task npmRun(type: Exec) {
commandLine "node", "node/index.js"
}
npmRun.dependsOn(build)
Step 2: After syncing your build.gradle in step 1 run the gradle tasks npmInit and npmInstall
./gradlew :npmInit
./graldew :npmInstall
Step 3:
Create your kotlin file (index.kt/main.kt/whatever.kt) in src/main/kotlin and test the code below
external fun require(module:String):dynamic
fun main(args: Array<String>) {
println("Hello JavaScript!")
val express = require("express")
val app = express()
app.get("/", { req, res ->
res.type("text/plain")
res.send("Kotlin/JS is kool")
})
app.listen(3000, {
println("Listening on port 3000")
})
}
Step 4: RTFA - Run The App
Run the gradle task npmRun
./gradlew :npmRun
Hope that helps
Note:
1. This template was pulled from the medium post you asked above and modified a little
2. Remember to run your gradle tasks using sudo (if you are using linux)
Edit: Alternatively, you could clone https://github.com/miquelbeltran/kotlin-node.js and follow the instructions in the read me.
I managed to get the Medium post to work by replacing gradle build with the following (since the post was published in 2017(!) and requires a much older version of Gradle):
Comment out the entire contents of build.gradle like so:
/*group 'node-example'
...
compileKotlin2Js.kotlinOptions {
moduleKind = "commonjs"
outputFile = "node/index.js"
}*/
Run this command in the command prompt: (3.4.1 was the latest version of Gradle just before the Medium post was published.)
gradle wrapper --gradle-version=3.4.1
Uncomment out build.gradle:
group 'node-example'
...
compileKotlin2Js.kotlinOptions {
moduleKind = "commonjs"
outputFile = "node/index.js"
}
Run this command in place of gradle build:
gradlew build
And finally run this command as in the post: (As of writing this answer on StackOverflow, Node.js does not be downgraded and the current LTS version 10.16.0 works perfectly.)
node node/index.js

How to detect when dependency library version updates exist in build.gradle in AndroidStudio project

I've an android project with two modules (typical front-end app and backend). I have three build.gradle files, one in each module and one in the root.
The way I've structured my dependencies is by extracting all the versions into separate variables in the root level build.gradle as such
ext {
// SDK and tools
MIN_SDK_VERSION = 19
TARGET_SDK_VERSION = 23
COMPILE_SDK_VERSION = 23
BUILD_TOOLS_VERSION = '24'
// app dependencies
GOOGLE_API_CLIENT_VERSION = '1.19.0'
GOOGLE_PLAY_SERVICES_VERSION = '8.4.0'
ANDROID_SUPPORT_LIB_VERSION = '23.1.0'
[...]
// backend dependencies
[...]
}
which are later used in my say app build.gradle file as such
dependencies {
[...]
compile(group: 'com.google.oauth-client', name: 'google-oauth-client', version: rootProject.ext.GOOGLE_API_CLIENT_VERSION)
/////////////////////////////////
// Google Play Services explicit dependency
compile(group: 'com.google.android.gms', name: 'play-services-auth', version: rootProject.ext.GOOGLE_PLAY_SERVICES_VERSION)
compile(group: 'com.google.android.gms', name: 'play-services-plus', version: rootProject.ext.GOOGLE_PLAY_SERVICES_VERSION)
[...]
/////////////////////////////////
// Local Testing
testCompile(group: 'junit', name: 'junit', version: rootProject.ext.JUNIT_VERSION)
testCompile(group: 'pl.pragmatists', name: 'JUnitParams', version: rootProject.ext.JUNIT_PARAMS_VERSION)
[...]
}
NOTE: I found that idea in a tutorial somewhere and I thought it was very nifty.
However, I'm struggling to keep track of which lib versions are available, what is upgradable, etc. It is becoming hard to keep track of these things as I have a reasonably sized list of dependencies. Curious how others have approached this problem. Thanks.
A summary of how I manage dependencies.
All dependency definitions are defined in gradle/dependencies.gradle, which is applied to all projects and the buildscript. I usually break it into three categories. A full example is here.
ext {
versions = [
caffeine: '2.3.1',
]
test_versions = [
testng: '6.9.12',
]
plugin_versions = [
versions: '0.13.0',
]
libraries = [
caffeine: "com.github.ben-manes.caffeine:caffeine:${versions.caffeine}",
]
test_libraries = [
testng: dependencies.create("org.testng:testng:${test_versions.testng}") {
exclude group: 'junit'
},
]
gradle_plugins = [
versions: "com.github.ben-manes:gradle-versions-plugin:${plugin_versions.versions}",
]
}
Then in my root project I bootstrap it as,
buildscript {
apply from: "${rootDir}/gradle/dependencies.gradle"
repositories {
jcenter()
}
dependencies {
gradle_plugins.each { name, dependency -> classpath dependency }
}
}
allprojects {
apply from: "${rootDir}/gradle/dependencies.gradle"
repositories {
jcenter()
}
}
This allows defining the dependency in a project as,
dependencies {
compile libraries.caffeine
}
To detect newer versions I wrote the gradle-versions-plugin. That generates a report by querying the repositories for the version information and comparing it to your definitions. I run it manually every so often, but others script it in their CI and use the json or xml reports.
There are a few other approaches that were developed after I wrote my plugin. Spring's dependency-management-plugin works with Maven BOMs, as does Netfix's nebula-dependency-recommender-plugin. Netflix uses gradle-dependency-lock-plugin to define dynamic versions and generate a lock file to fix a release. There are also dependency version alerting services, though a simple CI job is likely equivalent.
I've never used any of the alternatives as they seem less intuitive (to me), came out years after I had a nice solution, and it is a familiar approach if you come from Maven. Hopefully someone else can shed light on the benefits of other approaches.

Module missing in Android Studio and Gradle sync fails

I have set up a brand new project in Android Studio 1.1 RC 1:
Created an Android project [app] (because there is no way to create an App Engine backend project right away).
Added an existing backend module by first creating a new App Engine module and then manually importing the files [backend].
Removed the Android app module [app].
Added a Java library module, same procedure, first creating a new module, then importing files [common].
Everything compiles fine, but Android Studio has two problems:
When I look at Project Structure, the [common] module is missing in the left pane, but it still appears as referenced module in the right pane!?
My Project tree looks fine and all modules are recognized, but gradle is telling me the sync failed.
Gradle says "Task '' not found in root project" ('' is empty string as it seems). I get a Warning and an exception in the log when running from Terminal, but it doesn't seem to be related (related to Indexing), so I haven't included it here.
settings.gradle has both modules specified:
include ':backend', ':common'
I tried to exchange the .iml file of the main project with a fake one which contains both modules, with the result that (besides multiple side effects) both modules were there. (I restored the original state because of the side-effects.)
Here are my gradle files:
Root module:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
allprojects {
repositories {
jcenter()
}
}
[backend]
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.17'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.17'
compile 'com.google.appengine:appengine-endpoints:1.9.17'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.17'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.1.3'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.jsonwebtoken:jjwt:0.4'
compile project(':common')
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
[common]
apply plugin: 'java'
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
dependencies {
compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
compile 'com.google.code.gson:gson:2.3.1'
}
apply plugin: 'maven'
group = 'cc.closeup'
version = 'v2-2.0-SNAPSHOT'
install {
repositories.mavenInstaller {
pom.artifactId = 'common'
pom.packaging = 'jar'
}
}
Any ideas? Anything else that you'd like to see here?
If you want to build an AE project only. You could try this tutorial for intellij idea jetbrains.com/idea/help/creating-google-app-engine-project.html
My mistake was I removed [app]. It seems that if you create an App Engine backend module, you must keep a "fake" frontend module in the same project to keep Android Studio/gradle happy.
In earlier Android Studio versions it was possible to remove the frontend module without problems, but it seems Google has locked this somehow. It still works when I keep the fake frontend module.
--
Why I configured it this way? In my configuration, I have backend and frontend modules in different projects, and I have the backend project install libraries into local Maven, which I then pick up within my frontend project (with a team you would choose a local Maven server). This configuration has multiple advantages, for example that I can test backend/frontend on two screens simultaneously without switching back and forth all the time. Some companies may also want this configuration to keep their backend code separate and secure.

Resources