SBT Publish Customize Version String/Jar Name - sbt

I'm trying to publish some scala code to an artifactory repo, and I want to customize the jarname for the publish target.
When I modify the assembly/assemblyJarName it works when I run sbt assembly but as soon as I run sbt publish the jarname in artifactory doesn't match what I defined.
Why does sbt not use the defined jarname when publishing?
I changed the jarname in assembly/assemblyJarName and I expected the version I put in that value to be uploaded to artifactory.
The jar that ends up in artifactory looks like this: <package_name>_<scala_version>-<package_version>---assembly.jar
I can't figure out how to update the string that's uploaded to artifactory.
When I look at the logs from the CI system I see a message like this:
published pcakage_name_scala_version to https://artifactory.domain.com/artifactory/libs-snapshot-local;build.number=11;build.timestamp=1668632283151/com/org/package_name_scala_version/version_number-SNAPSHOT/package_name_scalaversion-version_number-SNAPSHOT-assembly.jar
So the file that's "uploaded" in the logs doesn't even match that artifat that's in artifactory.
There's some magic happening and it's not clear what

Related

AssemblyInfo ingrored when building from GitLab-Runner

On a Windows machine there is a GitLab-Runner run from a domain user with admin rights. When I log as this user and call dotnet build -c release to build an ASP.NET Core app, the dll has all the information from the AssemblyInfo.cs file. When I do the same as part of a CI job, the produced dll is missing all this information (for example the version number).
The AssemblyInfo.cs file is not part of the repository, instead, it is produced by a prebuild event (using gitWCRev.exe tool). However after running some tests I can see that the AssemblyInfo.cs is actually generated when the job is run by the runner.
Any help as to why the file is ignored and how to overcome this issue would be appreciated.
At first I thought that this might be related to Pre-build task of Visual Studio project fails in GitLab Runner issue, but I don't get any build errors.
On the same machine, I build a .Net Framework app which has the same AssemblyInfo setup, but is compiled using msbuild /property:Configuration=Release by the runner and the produced dll file has all the expected information.
It turns out the problem was partially related to the AssemblyInfo.cs file not being part of the repository.
SDK-style csproj normally don't list the files in the project, but figure them out based on the folder contents. When dotnet build was run, AssemblyInfo.cs wasn't present in the project directory (GitLab-Runner usually clears out files not present in the repository before starting a job/pipeline), so build tools had no idea they needed to load it. It made no difference that the file was being created by the build tools.
The solution proved to be creating an empty AssemblyInfo.cs file before running dotnet build. This way build tools knew they needed to compile it. Actual compilation still happened after prebuild events, so all the needed information was there.
I created the empty AssemblyInfo.cs file using PowerShell:
New-Item -Path "Properties/AssemblyInfo.cs" -ItemType File
Also, checking the build logs helped me finally figure it out. To get the build logs I've called build tools like this:
dotnet build -c release /flp:v=diag
The .Net Framework app didn't have this problem because it wasn't an SDK-style project. All the files needed for compilation were listed in the project file and build tools knew to load them, even if they were created during the prebuild event.

How to exclude folders/projects from dotnet core publish task in Azure Build Pipeline (Classic version)?

I have an Azure DevOps GIT Repo with three different types of projects. Structure looks as follows;
Repository Structure
I have a Build Pipeline (Classic, not YAML) to build only the .Net Core Project as below.
Pipeline
The pipeline settings is pointed to consider only the NetCoreProject. The Restore, Build & Test tasks executes successfully. However, when it comes to the 'Publish' task the pipeline fails as it considers the entire repository (all projects) and not just NetCoreProject.
Actual cause of failure is in NetCPPProject folder there are some files without any extension (makefile, shortcut files, etc.) which the Publish task is not identifying and failing with below error.
##[error]Error: Failed find: ENOENT: no such file or directory, stat 'D:\a\1\s\NetCPPProject\inc'
Note: inc is a shortcut file (without any extension) and it is required to be present in the folder.
I tried following which did not work;
Added .artifactignore to ignore other folders but the .Net Core 'Publish' task seems not to consider that.
Tried specifying the arguments to Publish tasks to consider only the NetCoreProject .sln file and also .csproj file, but issue still occurs with same error message.
Reconfirmed the file exists in Build.SourceDirectory with a command line task.
Question is, how to make .Net Core 'Publish' task to exclude NetCPPProject and only consider NetCoreProject?
how to make .Net Core 'Publish' task to exclude NetCPPProject and only consider NetCoreProject?
To achieve this goal, you could try the following steps:
Step1: Disable Publish web projects option in Dotnet Publish task.
Step2: Set the target csproj file in Path to project field
For example:
Repo:
Result:

Bitbucket pipelines: The type or namespace name could not be found

I'm hoping someone can help me out. Thanks!
I'm trying to deploy my dotnet core 2.0 API
When I try and build the project with bitbucket pipelines I get multiple errors finding references. It does restore the project successfully.
However the project builds successfully on my laptop.
folder structure:
/API
/Controllers
/Migrations
/Models
/Services
API.csproj
Program.cs
Startup.cs
bitbucket-pipelines.yml
pipelines:
default:
- step:
image: microsoft/dotnet
name: Check if it builds
script:
- cd API
- dotnet build
example error:
Services/MyService.cs(18,29): error CS0246: The type or namespace name 'IRepository<>' could not be found (are you missing a using directive or an assembly reference?) [/opt/atlassian/pipelines/agent/build/API/API.csproj]
Note I have the latest version of dotnet, same as I'm using in bitbucket pipelines. I have checked via running dotnet --info
Finally i've figured out what was the cause of this issue. I feel really silly for not figuring this out sooner.
My git repository was somehow setup with ignorecase = true.
I have switched it to false (which will prevent this issue in the future).
This means that I can have two of the same files or folders.
I had renamed a folder to a different case.
My repo had
API/
API.csproj
and
api/
api.csproj
My Mac couldn't allow for both so I only saw one folder and one project on my local machine.
To fix this, I had to git rm -r --cached api
This deleted the duplicate folder
I had the project file as a duplicate as well so used git rm -f api.csproj to remove the file from the repository.
Then git pull to bring those changes into my local master branch.

Deploying binaries from Bamboo to Nexus repository

Firstly I am new to Nexus. So please bear if it is too noob a question. Let me first explain how our current build/deployment process works.
HOW WE DO IT AT PRESENT:
We have a project that is Maven based. There is a parent POM.xml and two module pom.xmls Each child module POM.xmls create a JAR file each when built. Currently I am doing the build/ deployments manually. I checkout code from SVN to my local machine. I run mvn clean install. I have created a bash script to bundle the 2 Jar files + few other resources (Present just in SVN repo and gets downloaded to local) into a tar.gzip file. Now I SCP this to the app server. Run install scripts that deploys the tar.gzip file.
HOW WE WANT TO DO IT:
We plan to automate the build in Bamboo (Which I have already done). Then the built artifact needs to be uploaded to a Nexus repository (Due to security issues, the SCP task in Bamboo does not work because of establishing SSH connectivity from Bamboo Server to App Server).
MY FIRST HURDLE:
I have created a Bash Script task in Bamboo which does the bundling ( 2 Jars from each child Module POM + resources) to a tar.gzip. This tar.gzip is prersent in a path a/b/c/d on my bamboo machine.
How do I upload this tar.gzip to Nexus Repository?
MY CONFUSION:
I have read about uploading artifacts to Nexus. But I understand it if just 1 jar/ear/war file is created from the build. But we want the bundle. So if I make changes to settings.xml & POM.xml to configure the upload to NEXUS, each JAR file will be uploaded into separate paths in Nexus. And then I have to configure separately to upload the resource files (Not part of build). Is my understanding correct? Please let me know how to proceed with this?
Thanks in advance!!!
Use the Maven Assembly Plugin to create an assembly that contains your artifacts and resources, and then your regular maven deploy will deploy it into Nexus.

Deploy SNAPSHOT artifact and sources to Nexus from Maven command line

I am trying to deploy one EXE file and it's zipped source file to Sonatype Nexus using maven command line. Files must be deployed as SNAPSHOTs.
So, I have 2 files:
-testXYZ.exe and source file
-testXYZ.zip
Using maven 2.2.1 and command described here:
mvn deploy:deploy-file -Durl=file:///home/me/m2-repo \
-DrepositoryId=some.repo.id \
-Dfile=./path/to/artifact-name-1.0.jar \
-DpomFile=./path/to/pom.xml \
-Dsources=./path/to/artifact-name-1.0-sources.jar \
-Djavadoc=./path/to/artifact-name-1.0-javadoc.jar
I can deploy EXE, but cannot deploy source, because maven 2.2.1 is using deploy-plugin v2.5 and this command is not supported until v2.7.
It is not allowed to me to use newer versions of maven, so I try different approach.
Using these two subsequent commands I can deploy these two artifacts, but, source cannot be downloaded from nexus.
call mvn deploy:deploy-file -DgroupId=com.xyz -DartifactId=testXYZ -Dversion=1.1.116-SNAPSHOT -Dpackaging=zip -Dfile=testXYZ.zip -Dclassifier=sources -Durl=http://build:8081/nexus/content/repositories/snapshots -DrepositoryId=nexus
call mvn deploy:deploy-file -DgroupId=com.xyz -DartifactId=testXYZ -Dversion=1.1.116-SNAPSHOT -Dpackaging=exe -Dfile=testXYZ.exe -Durl=http://build:8081/nexus/content/repositories/snapshots -DrepositoryId=nexus
After deploy, i search for testXYZ and click on artifact source download link.
Nexus says:
"Item not found on path
"com.xyz:testXYZ:1.1.116-SNAPSHOT:c=sources:e=jar"!"
Problem is the way maven upload these artifacts:
Line form log file while source is uploading:
Uploaded: http://build:8081/nexus/content/repositories/snapshots/com/xyz/testXYZ/1.1.116-SNAPSHOT/testXYZ-1.1.116-20120106.111705-1-sources.zip
Line form log file while Main artifact is uploading:
Uploaded: http://build:8081/nexus/content/repositories/snapshots/com/xyz/testXYZ/1.1.116-SNAPSHOT/testXYZ-1.1.116-20120106.111709-2.exe
Notice 111705-1 and 111705-2. Last number must be the same if we wish Nexus can generate correct links.
This approach is described here:
Deploying an artifact, its sources and javadoc using maven's deploy:deploy-file plugin
and here:
http://maven.apache.org/plugins/maven-install-plugin/examples/installing-secondary-artifacts.html
and it working for fixed versions(for example 1.1.116), but not for SNAPSHOTs.
Exe and Zip files can be deployed to Nexus (like jar files), if fixed version is used.
So, question is:
Is there a way to deploy artifact and source SNAPSHOTs from command line to Sonatype Nexus and to be sure that these files can be downloaded by clicking on sources and artifacts links?
Note:
If I disable timestamps suffix, this can work, but I do not want to do this.
-DuniqueVersion=false
Thanks,
Marjan
I found partial solution for this problem. I can call specific version of maven-deploy-plugin like this:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file...
This way, artifacts and sources SNAPSHOTs can be deployed to Nexus avoiding any problems with download, but it behave like
-DuniqueVersion=false
is still there.

Resources